精华内容
下载资源
问答
  • 使用curl方式实现get或post请求 raw 方式请求 @param $url 请求的url地址 @param $data 发送的post数据 如果为空则为get方式请求 return 请求后获取到的数据 */ protected function curlRawRequest($url,$...
    /**
        使用curl方式实现get或post请求  raw 方式请求
        @param $url 请求的url地址
        @param $data 发送的post数据 如果为空则为get方式请求
        return 请求后获取到的数据
         */
        protected function curlRawRequest($url,$postFields)
        {
            $ch = curl_init($url);
    
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);
            curl_close($ch);
    
            return $result;
        }

    展开全文
  • http post 请求raw(字符串请求)

    千次阅读 2020-03-18 14:48:23
    HttpURLConnection //post字符串请求 public String HttpPost(String url, String rawBody){ HttpURLConnection conn = null; PrintWriter pw = null ; BufferedReader rd = null ; ...

    HttpURLConnection

        //post字符串请求
        public String HttpPost(String url, String rawBody){
    
            HttpURLConnection conn = null;
            PrintWriter pw = null ;
            BufferedReader rd = null ;
            StringBuilder sb = new StringBuilder ();
            String line = null ;
            String response = null;
            try {
                conn = (HttpURLConnection) new URL(url).openConnection();
                conn.setRequestMethod("POST");
                conn.setDoOutput(true);
                conn.setDoInput(true);
                conn.setReadTimeout(20000);
                conn.setConnectTimeout(20000);
                conn.setUseCaches(false);
                conn.setRequestProperty("Content-Type", "application/json");
                conn.connect();
                pw = new PrintWriter(conn.getOutputStream());
                pw.print(rawBody);
                pw.flush();
                rd  = new BufferedReader( new InputStreamReader(conn.getInputStream(), "UTF-8"));
                while ((line = rd.readLine()) != null ) {
                    sb.append(line);
                }
                response = sb.toString();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                try {
                    if(pw != null){
                        pw.close();
                    }
                    if(rd != null){
                        rd.close();
                    }
                    if(conn != null){
                        conn.disconnect();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return response;
        }
    
    
     fun postData1() {
            var url = "http://xxx:8082/basic-platform/schema/"
            var body = JSONObject()
            body.put("sn", "nlp_ai_capacity.xxxxx")
            body.put("query", "怎么办")
            var user_semantics = JSONObject()
            user_semantics.put("client_id", "orion.ovs.client.1514259512471")
            user_semantics.put("enterprise_id", "orion.ovs.entprise.2291039705")
            user_semantics.put("device_id", "nlp_ai_capacity_device")
            body.put("user_semantics", user_semantics)
            var json = body.toString()
    
            val thread: Thread = object : Thread() {
                override fun run() {
                    super.run()
                    try {
                        val post = HttpPostRaw().HttpPost(url, json)
                        println(post)
                    } catch (e: Exception) {
                        e.printStackTrace()
                        println(e.toString())
                    }
                }
            }
            thread.start()
        }
    

    HttpClients

    public static String httpPostRaw(String url, String stringJson, Map<String,String> headers, String encode){
            String str="";
            if(encode == null){
                encode = "utf-8";
            }
            //HttpClients.createDefault()等价于 HttpClientBuilder.create().build();
            CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
            HttpPost httpost = new HttpPost(url);
    
            //设置header
            httpost.setHeader("Content-type", "application/json");
            if (headers != null && headers.size() > 0) {
                for (Map.Entry<String, String> entry : headers.entrySet()) {
                    httpost.setHeader(entry.getKey(),entry.getValue());
                }
            }
            //组织请求参数
            StringEntity stringEntity = new StringEntity(stringJson, encode);
            httpost.setEntity(stringEntity);
            String content = null;
            CloseableHttpResponse httpResponse = null;
            try {
                //响应信息
                httpResponse = closeableHttpClient.execute(httpost);
                HttpEntity entity = httpResponse.getEntity();
                content = EntityUtils.toString(entity, encode);
                System.out.println(content);
                str=content;
            } catch (Exception e) {
                e.printStackTrace();
            }finally{
                try {
                    httpResponse.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {  //关闭连接、释放资源
                closeableHttpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    
        fun postData() {
            var url = "http://xxx/basic-platform/schema/"
            var body = JSONObject()
            body.put("sn", "nlp_ai_capacity.xxxxx")
            body.put("query", "怎么办")
            var user_semantics = JSONObject()
            user_semantics.put("client_id", "orion.ovs.client.1514259512471")
            user_semantics.put("enterprise_id", "orion.ovs.entprise.2291039705")
            user_semantics.put("device_id", "nlp_ai_capacity_device")
            body.put("user_semantics", user_semantics)
            var json = body.toString()
    
            val thread: Thread = object : Thread() {
                override fun run() {
                    super.run()
                    try {
                        HttpClientUtil.httpPostRaw(url, json, null, null)
                    } catch (e: Exception) {
                        e.printStackTrace()
                        println(e.toString())
                    }
                }
            }
            thread.start()
        }
    

    xutils3 post

        fun getAnswer(ask: String) {
            var body = JSONObject()
            body.put("sn", "nlp_ai_capacity.xxxxx")
            body.put("query", ask)
            var user_semantics = JSONObject()
            user_semantics.put("client_id", "orion.ovs.client.1514259512471")
            user_semantics.put("enterprise_id", "orion.ovs.entprise.2291039705")
            user_semantics.put("device_id", "nlp_ai_capacity_device")
            body.put("user_semantics", user_semantics)
         
            var params = RequestParams("http://xxxx/basic-platform/schema/")
            params.addHeader("Content-Type", "application/json")
            params.bodyContent = body.toString()
            println(params.toJSONString())
            x.http().post(params, object : Callback.CommonCallback<String> {
                override fun onFinished() {
                }
                override fun onSuccess(result: String?) {
                    if (result != null) {
                        var obj = JSONObject(result)
                    }
                }
                override fun onCancelled(cex: Callback.CancelledException?) {
                }
                override fun onError(ex: Throwable?, isOnCallback: Boolean) {
                }
            })
        }
    

    Cleartext HTTP traffic to xxx not permitted报错
    在清单文件中的application中添加

          android:usesCleartextTraffic="true"
    

    More than one file was found with OS independent path 'META-INF/DEPENDENCIES’报错
    排除掉中间生成的重复DEPENDENCIES.txt文件

    packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }
    
    展开全文
  • ajax请求中使用query方式来传递参数的案例:$.ajax({type: 'post',url: base_url + '/proced/addTemplate?templateName='+template_name,datatype: 'json',data: JSON.stringify(form_arr),co...

    0、Query

    通过query来传递参数,相当与在 url 地址后面拼接参数。ajax请求中使用query方式来传递参数的案例:$.ajax({

    type: 'post',

    url: base_url + '/proced/addTemplate?templateName='+template_name,

    datatype: 'json',

    data: JSON.stringify(form_arr),

    contentType : "application/json", //发送至服务器的类型

    success: function(data){

    if(data.status === 0){

    console.log(data);

    }

    }

    });

    1、form-data:

    等价于http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开。既可以上传键值对,也可以上传文件。当上传的字段是文件时,会有Content-Type来表名文件类型;content-disposition,用来说明字段的一些信息;

    由于有boundary隔离,所以multipart/form-data既可以上传文件,也可以上传键值对,它采用了键值对的方式,所以可以上传多个文件。

    png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgo8P3hwYWNrZXQgZW5kPSJyIj8+IEmuOgAAAA1JREFUCJljePfx038ACXMD0ZVlJAYAAAAASUVORK5CYII=

    2、x-www-form-urlencoded:

    等价于application/x-www-from-urlencoded,会将表单内的数据转换为键值对,比如,name=java&age = 23

    png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgo8P3hwYWNrZXQgZW5kPSJyIj8+IEmuOgAAAA1JREFUCJljePfx038ACXMD0ZVlJAYAAAAASUVORK5CYII=

    3、raw

    可以上传任意格式的文本,可以上传text、json、xml、html等

    png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAABS2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxMzggNzkuMTU5ODI0LCAyMDE2LzA5LzE0LTAxOjA5OjAxICAgICAgICAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIi8+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgo8P3hwYWNrZXQgZW5kPSJyIj8+IEmuOgAAAA1JREFUCJljePfx038ACXMD0ZVlJAYAAAAASUVORK5CYII=

    raw格式数据ajax请求的代码如下:$.ajax({

    type: 'post',

    url: base_url + '/student/updateStudent',

    data: JSON.stringify({

    'sid': sid,

    'batch_name': batch_name,

    'sname': sname,

    'clazz': clazz

    }),

    contentType : "application/json", //发送至服务器的类型

    dataType : "json",

    success: function(data){

    console.log(data);

    }

    });

    重点在于2点:1、使用JSON.stringify将对象转成字符串;2、添加这句话contentType : "application/json",点明发送至服务器的数据类型。

    4、binary

    相当于Content-Type:application/octet-stream,从字面意思得知,只可以上传二进制数据,通常用来上传文件,由于没有键值,所以,一次只能上传一个文件。

    multipart/form-data与x-www-form-urlencoded区别

    multipart/form-data:既可以上传文件等二进制数据,也可以上传表单键值对,只是最后会转化为一条信息;

    x-www-form-urlencoded:只能上传键值对,并且键值对都是间隔分开的。

    展开全文
  • <p style="text-align:center"><img alt="" height="727" src="https://img-ask.csdnimg.cn/upload/1608614965016.png" width="1918" /></p>  </p>
  • android post请求raw数据

    千次阅读 2020-06-16 10:07:07
    String url = "" String json = "{ "CheckItem": [ { "UserID":"30" }, { "UserID":"20" } ...HttpClient httpClient = new ...HttpPost post = new HttpPost(url); StringEntity postingString =...
    
    
    String url = ""
    String json = "{
      "CheckItem":
      [
          {
              "UserID":"30"
          },
          {
              "UserID":"20"
          }
      ]
    }";
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);
    StringEntity postingString = new StringEntity(json);
    post.setEntity(postingString);
    post.setHeader("Content-type", "application/json");
    HttpResponse response = httpClient.execute(post);
    String content = EntityUtils.toString(response.getEntity());
    
    

     

    展开全文
  • python接口请求post raw格式

    千次阅读 2019-02-21 23:40:50
    接口文档中写明接口请求方式为 post raw,python代码中的请求头中Content-Type应为application/raw,请求参数data是字典格式,故在post请求中用json.dumps()将参数转换成字符串...
  • 请求截图: 代码片段: public function actionXxxx(){ $symap = \Yii::$app->request->get(); $postData = file_get_contents('php://input'); }
  • 我在调用 RPC 接口时发生的一个小插曲 POSTMAN 中调试接口可行,但移到python脚本中却...对应 TCP 请求原文如下 POST http://192.168.41.131:8090/rpc HTTP/1.1 Accept-Encoding: identity Content-Type: applica...
  • 使用chrome浏览器的postman插件,post请求时有一个选项是f
  • java发送post请求raw形式和 Params形式发送

    千次阅读 热门讨论 2020-09-04 08:36:58
    在对接第三方平台时遇到了好几个坑,,发送raw形式的请求时一直返回参数不存在搞得我欲不痛生,,,,最后用另一种方法实现了 /** * header 在传输header时请务必加上charset=utf-8; * "Content-Type: ...
  • 废话不多说,先上两个工具类:用作普通的网络请求使用,文件的下载单独抽取一个工具类. public class HttpURLBuild { private final String TAG = "HttpURLBuild"; private String requestUrl = ""; private final ...
  • PHP中使用raw格式发送POST请求

    万次阅读 2018-03-07 11:41:56
    如果请求的参数格式是原生(raw)的内容,应该如何为程序构造一个POST请求函数呢?function http_post($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, ...
  • java跨域请求post raw参数请求

    千次阅读 2018-07-26 10:35:48
    public String cat(String josn,String url) throws ClientProtocolException, IOException { HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); ...
  • 调试微信推广支持中二维码生成api的接口,使用chrome浏览器的postman插件,post请求时有一个选项是form-data,或者raw,使用raw可以请求成功,from-data不知道怎么组装key和value所以一直失败。非常不明白raw是什么...
  • raw形式(body里面) RestTemplate restTemplate = new RestTemplate(); //请求头 HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("Content-Type", "application/json; charset=UTF-8");...
  • 原代码   HttpClient httpClient = new DefaultHttpClient();... HttpPost post = new HttpPost("http://*******.html");  StringEntity postingString = new StringEntity(json.toJSONString()...
  • postman raw模拟各种http post请求

    千次阅读 2020-06-08 16:45:37
    在url或者query里面传递参数 这个最简单 ... 上传表单key-value数据 ...1.使用自带的功能 ...2.使用raw来模拟 body设置 header设置不变 上传单个文件 1.使用自带功能 body设置 header设置 上传文件时C.
  • function http_post($url, $data_string) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, arr...
  • 发起post、get请求 /** * 发起请求 * @param string $url * @param string|array $ret 请求体 * */ private function http_req($url, $ret = '') { // 初始化 $ch = curl_init(); // 相关设置 curl_...
  • ajax请求 POST方式发送raw类型数据 $.ajax({ url:'url', type:"POST", dataType:"json", contentType: "application/json", data: JSON.stringify({ "data1": data1, "data2": data2 ...... }), success:...
  • 1、最近在重构部分旧...请求接口 public interface TestRetrofit2 { // 普通GET请求 @GET("/test1") Call<ResponseBody> test1(@Query("name") String name); // 结果利用ConverterFactory转换为对象

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 31,468
精华内容 12,587
关键字:

post请求raw