开发者

the request url cannot be retrieve?

i have send value to PHP from android with HttpPost but i get response "the request url cannot be retrieve"

this is my code

try {
            HttpClient client = new DefaultHttpClient();
            HttpPost post = new HttpPost(link);
            post.setEntity(new UrlEncodedFormEntity(sendValue));
            HttpResponse response = client.execute(post);
            Toast.makeText(this, response.getStatusLine().toString(),
                    Toast.LENGTH_LONG).show();
            if (response.getStatusLine().toString().contains("200")) {
                Toast.makeText(this, "Komentar berhasil dibuat",
                        Toast.LENGTH_LONG).show();
                finish();
            }
            else{
                Toast.makeText(this, "Koneksi server bermasalah",
 开发者_StackOverflow中文版                       Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            Log.e("log_tag", "Error connection" + e.toString());
        }

but if i remove "post.setEntity(new UrlEncodedFormEntity(sendValue));" i can connecting to PHP file..

how to solve this?

EDIT

i have set like this

private List<NameValuePair> sendValue = new ArrayList<NameValuePair>(4);
sendValue.add(new BasicNameValuePair("link", urlShare.toString()));
sendValue.add(new BasicNameValuePair("message", postComment.getText().toString()));
sendValue.add(new BasicNameValuePair("name", nameText.getText().toString()));
sendValue.add(new BasicNameValuePair("email", emailText.getText().toString()));


Check that the values that you are putting into sendValue are correctly encoded. You may also need to set the content type on your post object:

post.setHeader("Content-Type","application/x-www-form-urlencoded");


As dave.c said, most probably you rproblem is in the encoding. Try

String urlShareStr = URLEncoder.encode(urlShare.toString());
sendValue.add(new BasicNameValuePair("link", urlShareStr);

and the same for the rest. I separated into two commands only for the sake of reading it easier. You can condense it to

sendValue.add(new BasicNameValuePair("link", URLEncoder.encode(urlShare.toString());

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜