我的应用程序多年来一直使用相同的代码,它向我的JSON Web服务站点发送电子邮件地址和密码,然后检索给定的信息。我现在正在尝试发送一些额外的信息用于更新,但是当我添加两个额外的值时,应用程序崩溃了。
private void doTfr() {
String result = "";
String mailAddr = " ";
String feedback = " ";
String lectName = MyLecturesActivity.LectName;
String url = "http://jobtracker.myweb.com/jsonWeb/Default.aspx";
mailAddr = "s.chase@testweb.com";
EditText fBack = (EditText) findViewById(R.id.myfeedback_feedback2);
feedback = fBack.getText().toString();
lectName = "Test Android";
url = url + "?maddr=" + mailAddr + "&pwd=FB&lect=" + "\"lectName\"&fb=\"" + feedback + "\"";
//url = url + "?maddr=" + mailAddr + &pwd=BI"; Using this url works!
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url); ****Crashes here
HttpResponse response;
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = convertStreamToString(instream);
result = result.replaceAll(""", "\"");
JSONObject json=new JSONObject(result);
JSONArray nameArray=json.names();
JSONArray valArray=json.toJSONArray(nameArray);
endif
nstream.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
}
}
}
当我使用已注释掉的网址时,它可以正常工作。有人可以告诉我为什么添加这两个新值导致它崩溃,它可能是字符串的大小吗?
答案 0 :(得分:0)
您需要对该URL进行编码以处理引号。
String encodedUrl = URLEncoder.encode(url, "UTF-8");