我需要从一个天气预报的网站抽取数据,网站提供的格式如下
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();
}
}

解决方案 »

  1.   

    Socket实例化需要跟宽口,只有ip是不够的。
    另外getoutputstream方法貌似不跟参数的
      

  2.   

    看上面的英文,好像用Socket不行。
      

  3.   

    天啊,我彻底糊涂了,我该如何和这个服务器链接和交互哪?服务器接受的格式如下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>