[英]Get json object from API, modify & post it using C#
下面是我的代碼:
static void Main(string[] args)
{
SetBase();
//Console.ReadLine();
}
public static async void SetBase()
{
var baseAddress = new Uri("https://google.com/");
var httpClient = new HttpClient { BaseAddress = baseAddress };
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
var content = new StringContent("{ \"postUserLogin\":{ \"login\":\"username\", \"password\":\"password\", \"remember\":1,\"verify_level\":0 }}", System.Text.Encoding.Default, "application/json");
try
{
var response = await httpClient.PostAsync("/account/login", content);
using (var newresponse = await httpClient.GetAsync(viewURL + viewurlParameters))
{
if (newresponse.IsSuccessStatusCode)
{
string responseData = await newresponse.Content.ReadAsStringAsync();
JObject json = JObject.Parse(responseData);
//Get input from User
string input = Console.ReadLine();
//Make changes to json object according to input
//And Post Json object
}
}
}
catch (Exception ex)
{
}
}
之后的所有代碼: var response = await httpClient.PostAsync("/account/login", content);
不會被執行。
但是,如果我取消注釋Main
的Console.Readline()
行,其余步驟將被執行。 請幫忙。
是的,不要把它們放在一個循環中。 請添加將來不起作用的代碼,以避免您的問題被刪除。
按順序做:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.