我需要从一个天气预报的网站抽取数据,网站提供的格式如下
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.POST /globalweather.asmx/GetCitiesByCountry HTTP/1.1
Host: www.webservicex.net
Content-Type: application/x-www-form-urlencoded
Content-Length: length
CountryName=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">string</string>我写了如下的程序,可惜运行不了,一个问题是说没有socket类,可我明明import 了socket类啊,还有另一个问题,哪位能帮我改改import java.io.*;
import java.net.Socket;class TCPClient {
public static void main(String argv[]) throws Exception
{Socket clientSocket = new Socket("www.webservicex.net");
clientSocket.getOutputStream( " POST /globalweather.asmx/GetCitiesByCountry HTTP/1.1 Host: www.webservicex.net Content-Type: application/x-www-form-urlencoded Content-Length: length CountryName=china" );BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));clientSocket.close();
}
}
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.POST /globalweather.asmx/GetCitiesByCountry HTTP/1.1
Host: www.webservicex.net
Content-Type: application/x-www-form-urlencoded
Content-Length: length
CountryName=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">string</string>我写了如下的程序,可惜运行不了,一个问题是说没有socket类,可我明明import 了socket类啊,还有另一个问题,哪位能帮我改改import java.io.*;
import java.net.Socket;class TCPClient {
public static void main(String argv[]) throws Exception
{Socket clientSocket = new Socket("www.webservicex.net");
clientSocket.getOutputStream( " POST /globalweather.asmx/GetCitiesByCountry HTTP/1.1 Host: www.webservicex.net Content-Type: application/x-www-form-urlencoded Content-Length: length CountryName=china" );BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));clientSocket.close();
}
}
另外getoutputstream方法貌似不跟参数的
Host: www.webservicex.net
Content-Type: application/x-www-form-urlencoded
Content-Length: length
CountryName=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET">string </string>