HTTP-postを使用して値を送信していますが、例外が発生します。コードは次のとおりです。-
public static InputStream SendDetails(String senderEmail,String senderName,String senderPhone,String comment )
{
if(item != null)
{
url = constants.STATEURL + item.getListingid().toString()+"/contact";//?access_token=0|V1CALGARY|e98984a4c954fa1d78e3be626ad81a1d&mode=map";
}
else if(itemsavedfromdb != null)
{
url = constants.STATEURL + itemsavedfromdb.getListingid().toString()+"/contact";//?access_token=0|V1CALGARY|e98984a4c954fa1d78e3be626ad81a1d&mode=map";
}
else if(itemrecentfromdb != null)
{
url = constants.STATEURL + itemrecentfromdb.getListingid().toString()+"/contact";//?access_token=0|V1CALGARY|e98984a4c954fa1d78e3be626ad81a1d&mode=map";
}
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
nameValuePairs.add(new BasicNameValuePair("access_token",constants.accesstokenstate));
nameValuePairs.add(new BasicNameValuePair("mode","map"));
nameValuePairs.add(new BasicNameValuePair("senderEmail",senderEmail));
nameValuePairs.add(new BasicNameValuePair("senderName",senderName));
nameValuePairs.add(new BasicNameValuePair("senderPhone",senderPhone));
nameValuePairs.add(new BasicNameValuePair("comment",comment));
HttpPost request = new HttpPost(url);
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
return response.getEntity().getContent();
}このメソッドは次のように呼び出されます:-
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
mailHandler myhandler = new mailHandler();
xr.setContentHandler(myhandler);
String mailID = youremail.getText().toString();
if(mailID != null && !mailID.equalsIgnoreCase("") )
{
System.out.println("1");
ios = SendDetails(mailID,yourName.getText().toString(),yourPhoneNo.getText().toString(),yourMessage.getText().toString());
System.out.println("ios-----"+ios);
String strResponse = convertStreamToString(ios);
System.out.println("response"+strResponse);
xr.parse(new InputSource(ios));
resultmail = myhandler.emailresultdata();
customizeDialog = new CustomizeDialog(PropertyDetail.this);
customizeDialog.setTitle("Success");
customizeDialog.setMessage("Email send successfully");
customizeDialog.show();
データが正常に送信されなかったため、コードの上で例外が発生しました
次はスタックトレースです:-
07-03 09:02:15.264: WARN/System.err(491): java.io.IOException: Attempted read on closed stream.
07-03 09:02:15.275: WARN/System.err(491): at org.apache.http.conn.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:127)
07-03 09:02:15.275: WARN/System.err(491): at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:176)
07-03 09:02:15.275: WARN/System.err(491): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:516)
07-03 09:02:15.275: WARN/System.err(491): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
07-03 09:02:15.275: WARN/System.err(491): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
07-03 09:02:15.275: WARN/System.err(491): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)
07-03 09:02:15.275: WARN/System.err(491): at com.rentfaster.home.PropertyDetail.onClick(PropertyDetail.java:1623)
07-03 09:02:15.275: WARN/System.err(491): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 09:02:15.275: WARN/System.err(491): at java.lang.reflect.Method.invoke(Method.java:507)
07-03 09:02:15.275: WARN/System.err(491): at android.view.View$1.onClick(View.java:2139)
07-03 09:02:15.284: WARN/System.err(491): at android.view.View.performClick(View.java:2485)
07-03 09:02:15.284: WARN/System.err(491): at android.view.View$PerformClick.run(View.java:9080)
07-03 09:02:15.284: WARN/System.err(491): at android.os.Handler.handleCallback(Handler.java:587)
07-03 09:02:15.284: WARN/System.err(491): at android.os.Handler.dispatchMessage(Handler.java:92)
07-03 09:02:15.284: WARN/System.err(491): at android.os.Looper.loop(Looper.java:130)
07-03 09:02:15.284: WARN/System.err(491): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-03 09:02:15.284: WARN/System.err(491): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 09:02:15.284: WARN/System.err(491): at java.lang.reflect.Method.invoke(Method.java:507)
07-03 09:02:15.284: WARN/System.err(491): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-03 09:02:15.294: WARN/System.err(491): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-03 09:02:15.294: WARN/System.err(491): at dalvik.system.NativeStart.main(Native Method)
そして私のconvertStreamToStringメトスは次のとおりです:-
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return sb.toString();
}
誰もが私がどこで間違っているのか、そしてこれを行うための正しい方法を私に提案します。