httpClient在Windows Phone上不起作用 [英] httpClient doesn't work on Windows Phone

查看:93
本文介绍了httpClient在Windows Phone上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在使用"便携式"广告。 httpClient对象(与NuGet一起安装)以获取Web服务器上的php脚本的响应。

 Dim handler As New Http.HttpClientHandler 
Dim httpClient As New Http.HttpClient(handler)
Dim request As New Http.HttpRequestMessage(Http.HttpMethod.Post,"someurl / script.php")
Dim content As New Http.MultipartFormDataContent
content.Add(New Http.StringContent(" user") ,"username")
content.Add(New Http.StringContent(" 1234567890")," password")
request.Content = content
Dim response As Http.HttpResponseMessage =等待httpClient.SendAsync(request)
Dim result As String = Await response.Content.ReadAsStringAsync

问题是客户端没有得到响应,并且,在调试时,请求的requesturi属性似乎是空的......而stauscode属性是404"Not found"。 (我确定所请求的uri存在)


上述代码在Windows应用程序上运行正常。即使使用Windows Phone 7.1和8.0,我也试过这个代码,结果相同。最后我还尝试了httpclient.postasync方法......甚至没有响应。


我想使用httpclient,因为它支持async / await函数。


那么,有什么建议可以解决这个问题吗?


提前谢谢




Gianluca Concilio

解决方案



如果状态代码设置为404,通常意味着服务器收到了您的请求,并使用404 http代码进行响应。



1.因此要么重新检查网址两次,也许是一些空格/隐形符号,通过记事本复制/粘贴



2.检查PHP脚本 - 它也可以返回404作为某种错误指示。例如



php脚本试图找到你提供的用户名/传递并没有找到它们,所以它返回404 http代码,在这种情况下检查是什么"输入" php脚本



web服务也只对授权用户有效,未经授权他们返回404以显示"此页面不存在",在这种情况下他们可能需要http auth标头或某种会话cooke



3.很少见的问题,如果你在url中使用服务器名称 - 请检查你的网址本地计算机 - 如果它工作正常,那意味着您的DNS服务器将此名称解析为正确的IP地址,但您的手机可以连接到不同的网络,具有不同的
DNS服务器(甚至根本没有它,所以它无法解析名称),它可以为您提供另一个IP地址,当然脚本不存在,在这种情况下尝试URL中的显式IP地址



Hi all,

i'm using the "portable" httpClient object (installed with NuGet) to get the response of a php script on a web server.

        Dim handler As New Http.HttpClientHandler
        Dim httpClient As New Http.HttpClient(handler)
        Dim request As New Http.HttpRequestMessage(Http.HttpMethod.Post, "someurl/script.php")
        Dim content As New Http.MultipartFormDataContent
        content.Add(New Http.StringContent("user"), "username")
        content.Add(New Http.StringContent("1234567890"), "password")
        request.Content = content
        Dim response As Http.HttpResponseMessage = Await httpClient.SendAsync(request)
        Dim result As String = Await response.Content.ReadAsStringAsync

the problem is the client doesn't get the response, and, while debugging, the requesturi property of the request seems to be empty...while the stauscode property is 404 "Not found" (i'm sure that the requested uri exists)

the above code works fine on Windows apps. i've tried this code even with Windows phone 7.1 and 8.0, with the same result. finally i've also tried the httpclient.postasync method...even no response.

i want to use the httpclient because it supports the async/await functions.

so, any suggestion to solve this?

thanks in advance


Gianluca Concilio

解决方案

If status code is set to 404 it usually means that server got your request and responded with 404 http code.

1. So either re-check url twice, maybe some spaces/invisible symbols, copy/paste it via notepad

2. Check the PHP script - it also can return 404 as some kind of error indication. For example

php script tried to find user name/pass you supplied and didnt found them, so it returned 404 http code, in this case check what is on "input" of php script

also web service can be valid only for authorized users, for unauthorized they return 404 to show "this page doesnt exist for you", in such case they may need http auth header or some kind of session cooke

3. Rare problem, if you're using name of the server in url - check this url on your local computer - if it works ok, than it means you DNS server resolves this name into proper IP address, but your phone can be connected to different network, with different DNS server (or even without it at all, so it cannot resolve name), which can give you another IP address, where of course script doesnt exist, in this case try explicit IP address in URL


这篇关于httpClient在Windows Phone上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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