UWP getting HTTP 301 in windows mobile

强颜欢笑 提交于 2020-01-05 07:18:05

问题


I have this URL:

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

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

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"

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)

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();

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

Questions:

  1. Is this cause by my code or is it a bug in .NET?
  2. If it's my fault, how can I solve this?

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"

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.... "

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"

So again the reply is 301...

Impossible....


回答1:


Well, problem solved! :)

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...

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



来源:https://stackoverflow.com/questions/38247072/uwp-getting-http-301-in-windows-mobile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!