【发布时间】:2015-11-02 09:59:31
【问题描述】:
在我的 APIRequest 类中
if (paramBytes != null)
{
if(m_RequestMethod.equals("POST"))
{
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
out.write(paramBytes, 0, paramBytes.length); // to fix broken pipe
out.flush();
out.close();
}
}
和
case POST:
{
HttpPost request = new HttpPost(url);
// add headers
for (NameValuePair h : headers)
{
// request.addHeader(h.getName(), h.getValue());
request.setHeader(h.getName(), h.getValue());
}
// Add Parameters
if (params != null && !params.isEmpty())
{
request.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
}
if (entity != null)
{
request.setEntity(entity);
}
retVal = executeRequest(request, url);
break;
}
如何在 httpcilent 中添加此代码 要么 如何在http客户端中传递一个jsonobject 在 api 中有一个方法 setEntity() 在 http 中是否有可用的方法?
【问题讨论】:
-
你为什么不使用截击?现在有点正式了
-
http 已弃用,使用 volley 或改造等
标签: android api httpclient