0

我知道有一些关于这个主题的帖子,但我只能弄清楚我做错了什么。我必须通过邮寄一些参数到php server需要登录的 a 。

这是代码:

DefaultHttpClient httpclient = new DefaultHttpClient();
String postUrl = "http://dev.demo.fr/Contacts/areaGet.php";

HttpHost targetHost = new HttpHost("dev.demo.fr", 80, "http");

httpclient.getCredentialsProvider().setCredentials(
    new AuthScope(targetHost.getHostName(), targetHost.getPort()),
    new UsernamePasswordCredentials("*****", "*****"));
HttpPost httppost = new HttpPost(postUrl);
try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
    nameValuePairs.add(new BasicNameValuePair("language_id", "1"));
    nameValuePairs.add(new BasicNameValuePair("country_id", "1"));
    nameValuePairs.add(new BasicNameValuePair("postal_code", "42830"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    response = httpclient.execute(targetHost, httppost);
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}

System.out.println(response);

重要提示:用户名和密码uncoded在这里:

httpclient.getCredentialsProvider().setCredentials(
    new AuthScope(targetHost.getHostName(), targetHost.getPort()),
    new UsernamePasswordCredentials("*****", "*****"));

问题是当我这样做时:System.out.println(response); it prints out null我只是不知道为什么!!!!

谢谢您的回答!!!

4

1 回答 1

0

如果您从服务器收到响应“null”,则表示您的请求未成功发布在服务器上。

于 2012-05-21T08:11:50.243 回答