我正在使用commons-httpclient。 在我下面给出的android代码中,StringRequestEntity总是抛出不支持的编码异常的异常。但是上面的代码在java代码中执行时工作正常。但在android代码中给出了异常错误。这是进口
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
代码段
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(URL);
StringBuffer requestContent = new StringBuffer();
RequestObject requestObject = new RequestObject();
requestObject.setMobileNo("9999999999");
Gson gson = new Gson();
requestContent.append(gson.toJson(requestObject));
String requestContentString = requestContent.toString();
Log.d(TAG, "Request = " + requestContentString);
RequestEntity entity = new StringRequestEntity(requestContentString, "application/text", URL);
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}