我有一个从本地主机解析数据的应用程序,我将其中一个数据(名为 stuff
)发送到另一个 Activity (名为 WView
)。现在,在我的第二个 Activity ( WView
) 中,我想发送 stuff
到另一个链接。
我用过ArrayList<NameValuePair>
发送stuff
第一次到localhost,然后我把对象改成了字符串名stuff
仅用于测试目的。
现在的问题是,我正在使用以下代码。 “添加”于 postParameters.add(stuff.toString());
,有错误。
所以请告诉我我是否使用了 write 方式,或者如果它是错误的,请告诉我如何改正。 我将用于发送内容的代码从 WView 粘贴到另一个链接。
btLogout.setOnClickListener( new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(stuff.toString());
String response = null;
// call executeHttpPost method passing necessary parameters
try {
response = CustomHttpClient.executeHttpPost("http:example.com", postParameters);
}
catch (Exception e) {
Log.e("log_tag","Error in http connection!!" + e.toString());
}
}
});
最佳答案
正确的语法是:
postParameters.add(new BasicNameValuePair("key", Value));
根据您的情况,您需要更改为:
postParameters.add(new BasicNameValuePair("stuff", stuff.toString()));
关于java - 将 JSONObject 发送到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20257264/