无法使用System.NET.WebClient从源URL获取html响应 [英] Unable to get html response from source URL using System.NET.WebClient

查看:71
本文介绍了无法使用System.NET.WebClient从源URL获取html响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我通过Visual Studio 2010运行我的项目时,我的代码运行得非常好。但是当我在IIS 5上配置应用程序时,代码提供了以下内容例外:



无法连接到远程服务器。



在System.Net.WebClient.UploadValues (Uri地址,String方法,NameValueCollection数据)

在System.Net.WebClient.UploadValues(String address,String method,NameValueCollection数据)

at _Default.RunCrawler(String source,String keyword,String fileType)



System.Net.Sockets.SocketException(0x80004005):连接尝试失败,因为连接方在一段时间后没有正确响应时间或建立的连接失败,因为连接的主机无法响应111.111.222.19:80

在System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)
$ b System.Net.ServicePoint.ConnectSocketIn上的$ b ternal(布尔连接失败,插座s4,插座s6,插座& socket,IPAddress&地址,ConnectSocketState状态,IAsyncResult asyncResult,Int32超时,异常&例外)。



代码

WebClient webclient = new WebClient();

byte [] responseArray = webclient.UploadValues(some source URL,POST,values);

response = System.Text.Encoding.ASCII.GetString(responseArray);

解决方案

当我尝试在另一台服务器上运行代码时,源URL将数据作为特殊字符返回:



? ? ? ?`I%&安培;????/米{`JJT 

@ ?? IG#) * EVE F的@흼{{; N'\fdlJɞ??〜| ?????!? ?EYW〜R〜2 - ; YWW克?? W / / == O 2的컻w ^ ^'yyqNSӽOxsqe e39} ' ? S _T/? r |? O P > z < ϳ X M u~ G ] = {w5?7 V 6 . 2o ~ ; ? b 㬙 = ^ ?M <y ?f gO? ? ? }v ӓ {' N | zGi {ߵwMQZg 5u7<????öĴ ? = n ̏~b m^ iV/ E <k ]i x Y

_ ..ž〜ç?| N / qNYg_y}5ӺXi-/ ?A2 {?〜6ReϊO?? /小时?W * ^

+? NU,ލ97 NR}%ö1 + o7N:??] WWrV] z9m ?jNZW [뺼'7N〜6L〜U×< /克;; b瓦特;NJtK:????N-二8D / _,ԛdM&安培; . O ? .17

9 e j Zp:U > S | / | OiibF3 ^ N {S͗gǓ{???? ?N& ?? O > ? = 0 & ;; ?'R3R
?& ^ p6; ?L'{ ?> m ?9y | iI~ j l zz!d ' p ?u1_U}},`nTEV _>?!?!V + / UDA? ?= IV ??? 6Y:Y-1K-{u\e?
* vM iUV mTQ 9 ? }E }X R n X^ $ b $bM Z UI? # 。? r Я ң? U] t^ ? ik Uh ?da ?,Cϧ〜^ *#?? SBQ?(D?W'»F8ؙx2.Q 0 } ??( l?ťƛ]Ԩ72Me 4 }


Hi,

My code is running perfectly well when I run my project through Visual Studio 2010.But when I configure the application on IIS 5 the code gives following exception:

Unable to connect to the remote server.

at System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data)
at System.Net.WebClient.UploadValues(String address, String method, NameValueCollection data)
at _Default.RunCrawler(String source, String keyword, String fileType)

System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 111.111.222.19:80
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception).

Code
WebClient webclient = new WebClient();
byte[] responseArray = webclient.UploadValues("some source URL", "POST", values);
response = System.Text.Encoding.ASCII.GetString(responseArray);

解决方案

when I tried to run the code on another server machine, the source URL returns data as special characters as :

�      �`I�%&/m�{J�J��t��`


ؐ@������iG#)�*��eVe]f@�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"��Ey��w�������~R��~2����>y��W��w����g������W/���/���==���O����b���Ý컻�W�^�'���y���yq��N�S��ӽ�O�xsqe����e39}��'���S������_T/��r��|����O����P��>z<ϳ���X�M�u~��G�]=�{w57�V����6�.��2o�~��;��b��㬙��=��^M�<y��f����gO����������}v���ӓ�{'�N|z����Gi{��?���ߵw�M�QZ��g5�u�7�<o?J�=n��̏~b��m^���iV/��E����<k���]i�x��Y ���_�..?��Z����~C�|�N�/��q�N�Y���g_�y�}��5ӺX�i�-/��a���2{�~�6��Re�ϊ�O���?/hw��*�^��


+��n��U�,ލ���9�7NR}��%���o�<�+�o���7N.�:]�WW�rV]����z9m�j�N���Z�W[뺼�'��7N~�6�L~��U�������"�x��</.��g�;;��b��?�w��;�NJ�tK�:����N��-8�d��/���_���,ԛ��d �M˂&���.����O�㻻�٫17�� ��9���e�j�Zp:U>s���|��/|Oi�ib�F���3�^N�?��{S�͗�g�Ǔ����{��N&����O�>�����=��0������&;�'�3R �&��^�p6;�L'{�?>�m�����?9y��|��iI~���j�l ���zz!d��'�����p����u1�_�U}}�����,!�`�n�T�����EV_��>�!�V+�/�Ud����A=��iV���6��y:��Y^�K����{�u�\e� �����*����vM�����iUV�������mTQ�9���}E�}X��R���n�X^� M��ߐZ��UI��#��.�r��Я���ң��U]���t^����ik�Uh�da��� ��",�Cϧ�~�^*#S�bq(�����d˷��w����»�f�8��ؙx۲�.Q�0��}(���l ťƛ]Ԩ72Me�4�}


这篇关于无法使用System.NET.WebClient从源URL获取html响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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