UWP 在 Windows Mobile 中获取 HTTP 301 [英] UWP getting HTTP 301 in windows mobile

查看:22
本文介绍了UWP 在 Windows Mobile 中获取 HTTP 301的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个网址:

var url = "http://10.0.0.68/SET STB MEDIA CTRL {\"type\":\"tv\",\"action\":\"start query status\"}";
var newUri = new Uri(url);

这个 URI 的绝对路径是(来自 newUri):

Absolute path of this URI is (From newUri):

 http://10.0.0.68/SET%20STB%20MEDIA%20CTRL%20%7B%22type%22:%22tv%22,%22action%22:%22start%20query%20status%22%7D

我安装了 fiddler,当我在浏览器中输入这个网址时:

I installed fiddler and when I enter to the browser this url:

"http://10.0.0.68/SET STB MEDIA CTRL {"type":"tv","action":"start query status"}"

我可以看到,它被转换为这个网址:

I can see, that it is converted to this url:

 "http://10.0.0.68/SET%20STB%20MEDIA%20CTRL%20%7B%22type%22%3A%22tv%22%2C%22action%22%3A%22start%20query%20status%22%7D"

当我在 Windows 或手机模拟器上运行应用程序时,一切正常,但在 Windows Mobile 上运行时 - 收到错误 (301),当我尝试在 Chrome/Firefox 中打开绝对路径时 - 收到相同的错误(301)

When I run the app on Windows or mobile phone emulator all is working, but when running on Windows Mobile - getting an error (301), also when I am trying to open the absolute path in Chrome/Firefox - getting same error (301)

貌似在手机上运行的时候,字符串url转换错了,可以看到,绝对url和chrome/firefox的url是有区别的.问题是,这个字符 ":" 没有转换为 '3A'

It seems, when running on mobile phone, the string url is wrong converted, as you can see, there are difference between the absolute url and the url from chrome/firefox. The problem is, that this char ":" is not converted to '3A'

正如我已经写过的,我只在手机上有这个问题.

As I already wrote, I have this problem only on Mobile Phone.

 var client = new HttpClient();
 var url = "http://10.0.0.68/SET STB MEDIA CTRL {\"type\":\"tv\",\"action\":\"start query status\"}";
var uri = new Uri (url); //Just for debug
 var response = await client.GetAsync(url);
 var result = await response.Content.ReadAsStringAsync();

如果我使用 HttpClient 或 WebView 控件无关紧要 - 在 Windows Mobile 上 - 仍然是相同的错误 - 301

Does not matter if I use the HttpClient or WebView control - on Windows Mobile - still same error - 301

问题:

  1. 这是由我的代码引起的还是 .NET 中的错误?
  2. 如果是我的错,我该如何解决?

<小时>

好吧,我考虑了一下,发现我不需要使用 HttpClient - 我创建了套接字客户端 - 根据 microsoft 教程


well I thinked about it and I found, that I do not need to use HttpClient - I created socket client - according microsoft tutorial

我通过这个客户端模拟网络浏览器,但只发送简短的请求:

I simulate web browser via this client, but sending just short request:

var stringToSend =
            "GET /GET%20NOWORNEXT%20EPG%20%7B%20%22count%22%20%3A%20%2230%22%2C%20%22group%22%20%3A%20%225%22%2C%20%22epgNowOrNextFlag%22%20%3A%20%221%22%2C%20%22startIdx%22%20%3A%20%220%22%7D HTTP/1.1"

当我使用我从 PC 调试时,回复是正确的:

When I use I debug from PC the reply is correct:

"HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nDate: Fri, 08 Jul 2016 14:20:31 GMT\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n200 {\"group\":5,\"count\":30,\"data\": etc.... "

但从 Windows Mobile 手机结果是:

but from Windows Mobile phone the result is:

"HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nDate: Fri, 08 Jul 2016 15:42:01 GMT\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n301"

所以再次回复是 301...

So again the reply is 301...

不可能……

推荐答案

好了,问题解决了!:)

Well, problem solved! :)

它与 Windows Mobile 等无关...问题是,我必须第一次在连接到设备时只打开他的 IP 地址 f.e.通过 webView 等...然后我的 IP 暂时存储在设备中并愿意与我通信...从 PC 上它正在工作,因为我正在调试请求等...

It has nothing with Windows Mobile etc... The problem was, that I have to first time, when connecting to the device open just his IP address f.e. via webView etc.. then my IP is temporaly stored in the device and is willing to comunicate with me.. From PC it was working, because I was debuging the request etc...

我在设备上运行 logcat 并检查通信时找到了它!

I found it, when I run logcat on the device and was checking the communication!

这篇关于UWP 在 Windows Mobile 中获取 HTTP 301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆