62,046
社区成员
发帖
与我相关
我的任务
分享
public class GetData1 : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
//以下四种写法,都无法获取到post上来的参数,始终是null
string result = context.Request["abcd"]; //写法1
string result1 = context.Request.Params["abcd"]; //写法2
string result2 = context.Request.Form["abcd"]; //写法3
StreamReader streamReader = new StreamReader(context.Request.InputStream);
string result3 = streamReader.ReadToEnd(); //写法4
context.Response.ContentType = "text/plain";
context.Response.Write("传入:" + result + "," + result1 + "," + result2 + "," + result3);
}
}
public void getInfo(){
FormBody.Builder body = new FormBody.Builder();
body.add("abcd", "Mt_ktEdit");
final FormBody body1 = body.build();
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
String res = post(body1);
Message m = new Message();
m.obj = res;
m.what = GETINFO;
myHandler.sendMessage(m);
}
});
t.start();
}
public String post(FormBody body) {
String httpUrl = "http://192.168.5.112/GisYQMobile/RespondTomkmap.ashx";
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder()
.url(httpUrl)
.post(body)
.build();
String text = null;
Call call = okHttpClient.newCall(request);
try {
Response response = call.execute();
text = response.body().string();
} catch (IOException e) {
//e.printStackTrace();
String sss= e.getMessage();
}
return text;
}