public void getRemoteId(HttpServletRequest request,Model model){
String name = request.getParameter("userName");
String gender = request.getParameter("userGender");
String birthDate = request.getParameter("birthDate");
String birthHour = request.getParameter("birthHour");
String birthMin = request.getParameter("birthMin");
birthDate +=" "+birthHour+":"+birthMin;
String addrId = request.getParameter("borough");
String productId = request.getParameter("ProductId");
String birthDateAccurate = request.getParameter("BirthAccurateSelect");
String add_url = "http://test.com:8080/report.jo";
String query = " {\"mainUser\":{\"name\":\""+name+"\",\"gender\":\""+gender+"\",\"birthDate\":\""+birthDate+"\",\"birthDateAccurate\":\""+birthDateAccurate+"\",\"addrId\":\""+addrId+"\"},\"productId\":\""+productId+"\"}";
try {
URL url = new URL(add_url);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.connect();
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
JSONObject obj = new JSONObject(); String token = "d5f224c9f83874da5b5025794c773e8e";
obj.put("query", query);
obj.put("token", token);
out.writeBytes(obj.toString());
out.flush();
out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String lines;
StringBuffer sbf = new StringBuffer();
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sbf.append(lines);
}
System.out.println(sbf);
reader.close();
// 断开连接
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

java 发送http json请求的更多相关文章

  1. java发送http get请求的两种方式

    长话短说,废话不说 一.第一种方式,通过HttpClient方式,代码如下: public static String httpGet(String url, String charset) thro ...

  2. Java发送HTTP POST请求示例

    概述: http请求在所有的编程语言中几乎都是支持的,我们常用的两种为:GET,POST请求.一般情况下,发送一个GET请求都很简单,因为参数直接放在请求的URL上,所以,对于PHP这种语言,甚至只需 ...

  3. jQuery 发送 ajax json 请求。。

    $.extend({ postJson: function (data) { data = data || {} $.ajax({ type: "POST", url: data. ...

  4. java发送application/json格式的post请求,需要登陆

    package util; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWri ...

  5. Java 发送http post 请求

    package com.sm.utils; import java.io.BufferedReader; import java.io.InputStreamReader; import java.i ...

  6. java 发送get,post请求

    package wzh.Http; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStr ...

  7. Java发送HTTP POST请求(内容为xml格式)

    今天在给平台用户提供http简单接口的时候,顺便写了个调用的Java类供他参考.      服务器地址:http://5.0.217.50:17001/VideoSend 服务器提供的是xml格式的h ...

  8. JAVA发送http GET/POST请求的两种方式+JAVA http 请求手动配置代理

    java发送http get请求,有两种方式. 第一种用URLConnection: public static String get(String url) throws IOException { ...

  9. Java发送Http请求并获取状态码

    通过Java发送url请求,查看该url是否有效,这时我们可以通过获取状态码来判断. try { URL u = new URL("http://10.1.2.8:8080/fqz/page ...

随机推荐

  1. WPF之资源字典zz

    最近在看wpf相关东西,虽然有过两年的wpf方面的开发经验,但是当时开发的时候,许多东西一知半解,至今都是模模糊糊,框架基本是别人搭建,自己也就照着模板写写,现在许多东西慢慢的理解了,回顾以前的若干记 ...

  2. CodeForces 450B (矩阵快速幂模板题+负数取模)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51919 题目大意:斐波那契数列推导.给定前f1,f2,推出指定第N ...

  3. android开发 BaseAdapter中getView()里的3个参数是什么意思

    BaseAdapter适配器里有个getView()需要重写public View getView(int position,View converView,ViewGroup parent){ // ...

  4. linux中shell变量$#,$@,$*,$?,$$,$!,$_,$0,$1,$2的含义解释

    变量说明:    $$    Shell本身的PID(ProcessID)    $!    Shell最后运行的后台Process的PID    $?    最后运行的命令的结束代码(返回值)    ...

  5. event.keycode大全(javascript)

    keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter keycode 16 ...

  6. 【C语言】04-函数

    一.函数的分类 前面已经说过,C语言中的函数就是面向对象中的"方法",C语言的函数可以大概分为3类: 1.主函数,也就是main函数.每个程序中只能有一个.也必须有一个主函数.无论 ...

  7. GDB打印STL容器内容

    GDB调试不能打印stl容器内容,下载此文件,将之保存为~/.gdbinit就可以使用打印命令了. 打印list用plist命令,打印vector用pvector,依此类推. (gdb) pvecto ...

  8. hdu1272 并查集

    如果要输出yes 需要满足 1  这个图连通 2  没有回路 3  0 0 也是yes 看它有没有回路 在un的时候做一次判断就可以了 然后是判断连通 在这里采用的方法是扫一遍 如果这个点出现过就判断 ...

  9. Apache Spark技术实战之2 -- PackratParsers实例

    欢迎转载,转载请注明出处,徽沪一郎 概要 通过一个简明的Demo程序来说明如何使用scala中的PackratParsers DemoApp import scala.util.parsing.com ...

  10. 程序设计第二次作业<1>

    面向对象程序设计第二次作业<1> Github 链接:https://github.com/Wasdns/object-oriented 题目: <1>第一次尝试 我立马认识到 ...