我知道有一些关于这个主题的帖子,但我只能弄清楚我做错了什么。我必须通过邮寄一些参数到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
我只是不知道为什么!!!!
谢谢您的回答!!!