Java HTTP POST在Android中不起作用

Java HTTP POST在Android中不起作用,java,android,http-post,Java,Android,Http Post,我遇到了同样的问题-您需要在POST的帮助下将用户添加到数据库中。我做的一切都和IPhone一样——但我的android实现由于某种原因无法工作——服务器上的用户无法保存 请告诉我有什么问题?我希望得到你的帮助 Android HTTP POST: public void postData() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("

我遇到了同样的问题-您需要在POST的帮助下将用户添加到数据库中。我做的一切都和IPhone一样——但我的android实现由于某种原因无法工作——服务器上的用户无法保存

请告诉我有什么问题?我希望得到你的帮助

Android HTTP POST:

 public void postData() {        
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://&&&&&&&.dk/accounts/save_user/");
    try {
        facebookUserInfo = new JSONObject(mFb.request("me"));
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        try {
            nameValuePairs.add(new BasicNameValuePair("fbuid", facebookUserInfo.getString("id")));
            nameValuePairs.add(new BasicNameValuePair("first_name", facebookUserInfo.getString("first_name")));
            nameValuePairs.add(new BasicNameValuePair("last_name ", facebookUserInfo.getString("last_name")));
            System.out.println(facebookUserInfo.getString("id")+" "+facebookUserInfo.getString("first_name")+" "+facebookUserInfo.getString("last_name"));
        }
        catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getEntity()+" "+response.getStatusLine());

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}
   NSURL *url = [NSURL URLWithString:@"http://&&&&&&&&&.dk/accounts/save_user/"];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    //[request setPostValue:myAnnotation.google_id forKey:@"google_id"];
    [request setPostValue:fbuid forKey:@"fbuid"];
    [request setPostValue:_fbFirstName forKey:@"first_name"];
    [request setPostValue:_fbLastName forKey:@"last_name"];

    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(@"%@",response);
    } 

我已经把你的解决方案变成了将来帮助别人的答案

问题就在这方面

添加(新的BasicNameValuePair(“last_name”,facebookUserInfo.getString(“last_name”))

问题是由钥匙
姓氏
中的间隙(空格)引起的。因此,要修复此方法,
EntityUtils.toString(httpPost.getEntity()
将返回一个结果行

fbuid=10000434390749&first\u name=Proba&last\u name+=Proba

修正后


fbuid=10000434390749&first\u name=Proba&last\u name=Proba

“不起作用”?这是什么意思?你在android清单文件中添加了互联网权限了吗?@Chirag Raval:included问题仍然相关