1. 程式人生 > >C# Post請求json資料

C# Post請求json資料

//以html post方式請求json資料

private string Post(string strURL, string auth, string contentType, string jsonParas)

        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
            httpWebRequest.ContentType = contentType;//application/json
            httpWebRequest.Method = "POST";
            WebHeaderCollection whc = new WebHeaderCollection();
            whc.Add(auth);//authorization:xxx
            httpWebRequest.Headers.Add(whc);


            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(jsonParas);
                streamWriter.Flush();
                streamWriter.Close();
            }


            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                return streamReader.ReadToEnd();
            }

        }

推薦一款外掛(google Advanced Rest Client),可用於測試請求/響應結果。

相關推薦

C# Post請求json資料

//以html post方式請求json資料 private string Post(string strURL, string auth, string contentType, string jsonParas)         {             var h

python中post請求json資料且返回json資料處理

上篇講到以json形式傳送post請求。 此次為 post請求返回物件對json 時的處理辦法 請求 #請求 response = requests.post(url, data=json.dumps(pyload),headers=headers).text

Java獲取post請求json資料

一般情況下,web應用中,瀏覽器傳送http請求,傳引數的時候都是作為param傳遞的,java服務端通過request.getParameter(name)可以獲取引數內容; 但是會有一些場景,把引數放在了http的payload中(contentType:”application/json”),這時,使

c# post請求獲取json資料

        /// <summary>         /// get http請求獲取位置資訊         /// </summary>         interna

c#後臺發post請求獲取資料

C#進階系列——WebApi 介面引數不再困惑:傳參詳解 閱讀目錄 一、get請求 1、基礎型別引數 2、實體作為引數 3、陣列作為引數 4、“怪異”的get請求 二、post請求 1、基礎型別引數

關於C#向伺服器請求json資料並解析

查了一下午+一晚上,什麼樣的回答都有,好些讓我感到十分無語。趕專案,沒總結出太高大上的用法,下面簡單講一下。 請求用的GET方法 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); WebRespons

soapUI傳送post請求json格式,返回請求資料為空

使用soupUI傳送post請求,活的結果告訴請求引數為空,意思就是沒有請求到body的內容,但是用postman等工具都是正常的。於是,檢視系統介面日誌。提示獲取http請求的body失敗。網上查詢第二句話,”java.nio.charset.MalformedInputE

vue中的axios.post使用json資料傳輸,出現請求頭欄位內容型別是不被允許的情況的解決方案

問題描述: 由於restful介面需要在頭部header傳遞兩個欄位: Content-Type: application/json Access-Token: 84c6635800b14e0eba4f7ece65e095a1 但是,在vue.js裡面配置: 執行傳送的時候出現: 意思是

httpclient模擬post請求json封裝表單數據

readline turn ast acc [] 選擇 encoding 效率 set 1 public static String httpPostWithJSON(String url) throws Exception { 2 3

【日記】c# 讀取網頁json資料

例:讀取雙色球官網歷史開獎號碼資料 1.準備工作 web url:  http://www.cwl.gov.cn/kjxx/ssq/kjgg/ 按F12在網路面板得到如下資料 json url: http://www.cwl.go

原生AJAX 請求JSON資料方式

這裡先給大家一個有實際json資料的連線: https://jsonplaceholder.typicode.com/posts 1.例項化XMLHttpRequest物件 var request; if (window.XMLHttpRequest) {   request = new

vue 處理後臺請求json資料,並渲染

後臺傳給前臺的json資料格式,這裡原本只是傳list資料給後臺,因為需要分頁,所以用pageInfo包了一下,成了json格式: { "data": { "endRow": 1, "firstPage": 1, "hasNextPage": false,

mongoDB + flask 儲存前端 post 請求資料

python file:  from flask import Flask,render_template,url_for, request, redirect from logging import DEBUG from datetime import datetime

HttpUtils工具類和post請求json引數傳輸

import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.client.ResponseH

SpringMVC筆記九之ajax請求json資料

1、匯入jackson-annotations-2.2.1.jar,jackson-core-2.2.1.jar,jackson-databind-2.2.1.jar三個jar包,注意他們的版本要一致,不然會報錯。https://download.csdn.net/downl

jQuery.ajax設定請求頭實現post請求傳送資料的格式(Form Data和Request Payload)

 Request Payload 請求頭部的 Content-Type: application/json,請求正文是一個 json 格式的字串 Form Data 請求頭部的 Content-Typ

python3 服務端使用CGI指令碼處理POSTJson資料

傳送端程式碼 #!/usr/bin/env python3 #coding=utf-8 #agent.py import requests import json import urllib.requ

Java傳送HTTP的get,post請求(JSON)

Java傳送HTTP的get,post請求(JSON) import net.sf.json.JSONObject; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.met

Linux--Shell指令碼逐行讀文字處理並curl傳送post請求json格式等問題

問題:Shell指令碼逐行讀取文字,字串分割,Curl傳送Post請求Json格式等相關問題 在linux中使用curl傳送一個post請求時,帶有json的資料,在傳送時發現json中的變數沒有解析出來: curl -d '{"Pin": "${line}"}' -H"

ajax基於php頁面請求json資料

在jQuery中封裝有$.ajax方法可以直接來呼叫  ·testjson.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title