記錄Post Form Data

2022-09-23 08:07:08 字數 2388 閱讀 7826

if (string

.isnullorempty(configmgr.wxplatformtoken))

uri urluri = new uri(wxplatformconfig.baseurl +wxplatformconfig.tokenpath);

namevaluecollection nvc = new

namevaluecollection();

nvc.add(

"grant_type

", "

password");

nvc.add(

"username

", wxplatformconfig.tokenuser);

nvc.add(

"password

", wxplatformconfig.tokenpwd);

string boundary = createformdataboundary(); //

邊界符byte beginboundarybytes = encoding.utf8.getbytes("

--" + boundary + "

\r\n

"); //

邊界符開始。【☆】右側必須要有 \r\n 。

byte endboundarybytes = encoding.utf8.getbytes("

--" + boundary + "

--\r\n

"); //

邊界符結束。【☆】兩側必須要有 --\r\n 。

byte newlinebytes = encoding.utf8.getbytes("

\r\n

"); //

換一行httpwebrequest httpwebrequest = null

;

try"

, boundary);

httpwebrequest.method =webrequestmethods.http.post;

httpwebrequest.keepalive = true

; httpwebrequest.timeout = -1

; httpwebrequest.servicepoint.expect100continue = false

; httpwebrequest.proxy = null

;

string formdatatemplate = "

content-disposition: form-data; name=\"\"\r\n\r\n

" + "

\r\n";

memorystream memorystream = new

memorystream();

foreach (string key in

nvc.keys)

memorystream.write(endboundarybytes,

0, endboundarybytes.length); //

2.4 寫入formdata的結束邊界符

httpwebrequest.contentlength =memorystream.length;

stream requeststream =httpwebrequest.getrequeststream();

memorystream.position = 0

;

byte tempbuffer = new

byte

[memorystream.length];

memorystream.read(tempbuffer,

0, tempbuffer.length);

memorystream.close();

requeststream.write(tempbuffer,

0, tempbuffer.length); //

將記憶體流中的位元組寫入 httpwebrequest 的請求流中

requeststream.close();

httpwebresponse httpwebresponse = httpwebrequest.getresponse() as httpwebresponse; //

獲取響應

if (httpwebresponse != null

) }}

catch

(exception ex)

Log POST Data in Nginx

先編譯nginx的echo module configure add module echo nginx module 0 54 make...

angular form data檔案上傳

前言 很久沒更新部落格,最近公司pc端技術選型用angular 這幾天就趕鴨子上架,硬著頭皮直接上手angular。其中有許多小坑陸陸續續踩...

form get和post解釋

在html中,form元素用method屬性來指定有兩種不同的提交方法,即 get 預設值 和 post 。 w3c的html 4 01 s...