在我的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;
}
型
如何在httpclent中添加此代码
或
如何在HTTP客户端中传递JSON对象
在API中,有一个方法setEntity()
在HTTP中有什么方法可用吗?
1条答案
按热度按时间wd2eg0qa1#
创建json对象,然后调用jsonobj.put(key,value)创建一个数组列表,调用listobj.put(key,jsonob.tostring())