Home > Back-end >  Java HttpURLConnection failure problem
Java HttpURLConnection failure problem

Time:04-08

Try
{
URL the URL=new URL (" http://www.diankongyixian.com/WBWX/UI/DataServices/IDataServicesForWeChat.ashx ");
The connection url=(HttpURLConnection). The openConnection ();//based on the URL generated HttpURLConnection
Connection. SetRequestMethod (" GET ");//the default GET request
Connection. The connect (); TCP connection to//

If (connection. GetResponseCode ()==HttpURLConnection. HTTP_OK)
{
Reader=new BufferedReader (new InputStreamReader (connection. GetInputStream (), "utf-8"));
The StringBuilder result=new StringBuilder ();

//loop reads the flow
While ((line=reader. ReadLine ())!=null)
{
Result. Append (line). Append (System. GetProperty (" line. The separator "));//"\ n"
}

System. The out. Println (result. The toString ());
}
}

connection getResponseCode always return 400, tracking is found in such as images of error

,
The master know how to solve? thank you

CodePudding user response:

I am a Swing in the Java desktop application create HTTP access client classes

CodePudding user response:

Access to the address is on the Internet
  • Related