Home > Net >  The Http request cannot link to a remote server
The Http request cannot link to a remote server

Time:10-30

 public void PrintLabel (string jsonParas, string url) 
{
//create an HTTP request
HttpWebRequest request=(HttpWebRequest) WebRequest. Create (url);
//Post request way
Request. The Method="POST";
//content type
Request. ContentType="application/json";

//set parameters and URL encoding

String paraUrlCoded=jsonParas;//System. Web. HttpUtility. UrlEncode (jsonParas);

Byte [] content;
//convert Json string into bytes
Content=System. Text. Encoding. UTF8. GetBytes (paraUrlCoded);
//set the request ContentLength
Request, ContentLength=payload Length;
//send the request, the request flow

The Stream writer;
Try
{
Writer.=the request GetRequestStream ();//get used to write the request data Stream object
}
The catch (Exception ex)
{
Writer=null;
The Console. Write (" connect to the server failed!" );
MessageBox. Show (ex. The Message, "prompted", MessageBoxButtons. OK, MessageBoxIcon. Warning).
return;
}
//write request parameter inflow
Writer. Write (payload, 0, payload. Length);
Writer. The Close ();//close the request flow
//String strValuehttps://bbs.csdn.net/topics/="";//strValue into the HTTP response stream of characters returned by
HttpWebResponse response;
Try
{
//get the response flow
The response=(HttpWebResponse) request. The method GetResponse ();
}
The catch (WebException ex)
{
The response=ex. The response as HttpWebResponse;
}
The Stream s=response. GetResponseStream ();
//the Stream postData=https://bbs.csdn.net/topics/Request.InputStream;
StreamReader sRead=new StreamReader (s);
String postContent=sRead. ReadToEnd ();
SRead. Close ();
}

This on the web project can run normally, access to the same URL, postman can run normally, but I put this code in winform project, suggests that cannot link to a remote server, specific hint is: because the target machine actively refused, cannot link,
Later I use Fidder ready to look at the link sent out no, result I opened Fidder he can connect again, I look at the next agent, opened a Fidder opens agent: 127.0.0.1:8888 can connect so, close the agent cannot connect again, same computer web project and postman can normal visit, not just web project, what's the problem? How to solve

CodePudding user response:

I guess, the service side climb the steps to set up UA validation, Fidder forward time may request for the modification, increased the UA.
You try postman export to try the code to run. (or modify request header and increase UA)

CodePudding user response:

reference 1st floor ziqi0716 response:
, I guess the server's climb the steps to set up UA validation, Fidder forward time may request for the modification, increased the UA.
You try postman export to try the code to run. (or modify request header and increase UA)

What you said is UA UserAgent, I put him in accordance with the postman set up or not

CodePudding user response:

Described above is me has a problem, and set up the agent not too big relations, I set the agency closed Fidder is inaccessible, must open Fidder

CodePudding user response:

Netstat look at the port, the firewall open access or closed,

CodePudding user response:

refer to the second floor BXS_null response:
Quote: refer to 1st floor ziqi0716 response:
, I guess the server's climb the steps to set up UA validation, Fidder forward time may request for the modification, increased the UA.
You try postman export to try the code to run. (or modify request header and increase UA)

What you said is UA UserAgent, I put him in accordance with the postman set up or not

Well, why don't you send the url we try...

CodePudding user response:

reference 5 floor ziqi0716 reply:
well, why don't you send the url we try...

no
  •  Tags:  
  • C#
  • Related