简体   繁体   English

URL 字符串的正确格式

[英]Proper format of a URL String

What is a proper URL for accessing a HTTP Server?访问 HTTP 服务器的正确 URL 是什么?

byte[] vs = new HttpClient().GetBytes("192.168.1.22:8080/myDataCollection.xml");
var bytes = vs;
CrestronConsole.PrintLine("bytes : {0}", bytes);
return bytes.ToString();

this gives me an error that the string is not valid.这给了我一个字符串无效的错误。

As Hans says in the comment - the issue is that you aren't providing the protocol in the URL, try:正如汉斯在评论中所说 - 问题是您没有在 URL 中提供协议,请尝试:

byte[] vs = new HttpClient().GetBytes("https:192.168.1.22:8080/myDataCollection.xml");

Also, it's worth noting that the method you've written will not return the XML string.此外,值得注意的是,您编写的方法不会返回 XML 字符串。 If you want the method to return the XML string you'll need to do it this way (replacing Default with the relevant encoding):如果您希望该方法返回 XML 字符串,您需要这样做(用相关编码替换Default ):

string xmlString = System.Text.Encoding.Default.GetString(vs);
return xmlString;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM