第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

它在郵遞員網(wǎng)絡(luò)中工作,但在代碼中不起作用

它在郵遞員網(wǎng)絡(luò)中工作,但在代碼中不起作用

C#
白板的微信 2022-12-24 12:52:07
我嘗試使用郵遞員連接 REST API,這總是一個(gè)很好的請求。沒問題。但是,在其余的實(shí)現(xiàn)代碼中,我總是收到錯(cuò)誤“StatusCode: Unauthorized, Content-Type: text/plain; charset=utf-8, Content-Length: 0)”。我嘗試了很多方法來做到這一點(diǎn),但從未完成。//url = url server//authorization = Bearer .....//body = text json var client = new RestClient(url);var request = new RestRequest(Method.POST);request.AddHeader("content-type", "application/json");request.AddHeader("authorization", authorization);request.AddParameter("application/json", body, ParameterType.RequestBody);IRestResponse response = client.Execute(request);var result = response.Content;在郵差、
查看完整描述

1 回答

?
飲歌長嘯

TA貢獻(xiàn)1951條經(jīng)驗(yàn) 獲得超3個(gè)贊

我正在使用 HttpWebRequest,但我認(rèn)為也可以使用 RestClient。


我使用 Fiddler 識別郵遞員請求中的標(biāo)頭,然后在代碼中回復(fù)此標(biāo)頭。


下面的代碼對我有用。


我會做一些改變,但僅此而已。



//url = url server

//authorization = Bearer .....

//body = text json 

//bytesBody = body in byte[]


HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);

webRequest.PreAuthenticate = true;

webRequest.Method = "POST";


webRequest.Headers["Cache-Control"] = "no-cache";

webRequest.Accept = "*/*";

webRequest.Headers["Accept-Encoding"] = "gzip, deflate, br";


webRequest.Headers["Accept-Language"] = "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7";

webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";

webRequest.ContentType = "application/json";


webRequest.ContentLength = bytesBody.Length;

webRequest.Headers["authorization"] = authorization;

//webRequest.Headers["Origin"] = "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop";


webRequest.KeepAlive = true;

webRequest.ServicePoint.Expect100Continue = false;

webRequest.Host = host;



using (Stream dataStream = webRequest.GetRequestStream())

{

    dataStream.Write(bytesBody, 0, bytesBody.Length);

    dataStream.Flush();

    dataStream.Close();

}


WebResponse response = webRequest.GetResponse();


using (var streamReader = new StreamReader(response.GetResponseStream()))

{

    string result = streamReader.ReadToEnd();

}

response.Close();


查看完整回答
反對 回復(fù) 2022-12-24
  • 1 回答
  • 0 關(guān)注
  • 85 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號