import net.sf.
json.
JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.
HttpClient;
import org.apache.http.client.methods.Http
Post;
import org.apache.http.
entity.
StringEntity;
import org.apache.http.impl.client.
HttpClientBuilder;
//
StringEntity s = new
StringEntity(dataStr);
// s.
setContentEncoding("UTF-8");
// s.
setContentType("
application/
json");
privatevoidhttpReqUrl(List<HongGuTan>list,Stringurl)
throwsClientProtocolException,IOException{
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.Log;
import android.text.TextUtils
import android.util.Log
import com.alibaba.fastjson.JSONException
import com.google.gson.Gson
import okhttp3.*
import okhttp
requests通过post请求,设置headers = {‘Content-Type’: ‘application/json’ }未生效问题
1、requests中,设置headers参数{‘Content-Type’: ‘application/json’ },是将请求数据以json的格式发送,而headers中默认请求方式是表单提交:{‘Content-Type’: ‘application/x-www-form-urlencoded’ };
设置了headers = {‘Content-Ty
结果运行后发现$_
POST数组为空!
百度之后发现是
content-type为"
application/
json"的数据php是不能直接识别的,所以导致$_
POST数组为空
解决办法:我们只要用$GLOBALS['HTTP_RAW_
POST_DATA']把原始数据取出来,然后再
json_decode就行了
//request.getParameterNames();
br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8"));