Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HTTP调用中的内容类型_C#_.net_Rest_Httpresponse_Http Put - Fatal编程技术网

C# HTTP调用中的内容类型

C# HTTP调用中的内容类型,c#,.net,rest,httpresponse,http-put,C#,.net,Rest,Httpresponse,Http Put,我的HTTP Put调用响应由以下代码打印 HttpResponseMessage response = await client.PutAsync("https://restapi.surveygizmo.com/v4/survey/2692209/surveypage/3/surveyquestion?", inputMessage.Content); string returnString = response.ToString(); Console.WriteLine(returnSt

我的HTTP Put调用响应由以下代码打印

HttpResponseMessage response = await client.PutAsync("https://restapi.surveygizmo.com/v4/survey/2692209/surveypage/3/surveyquestion?", inputMessage.Content);

string returnString = response.ToString();
Console.WriteLine(returnString);
Console.WriteLine(response.StatusCode);

我想打印要在console或其他格式上打印的内容类型信息。基本上我希望看到c#中的内容类型。如何做到这一点?

使用响应()中存储的Content.Headers.ContentType信息

例如,要将控制台类型写入控制台,请执行以下操作:

HttpResponseMessage response = await client.PutAsync("https://restapi.surveygizmo.com/v4/survey/2692209/surveypage/3/surveyquestion?", inputMessage.Content);

Console.WriteLine(response.Content.Headers.ContentType);

通过使用响应()中存储的Content.Headers.ContentType信息

例如,要将控制台类型写入控制台,请执行以下操作:

HttpResponseMessage response = await client.PutAsync("https://restapi.surveygizmo.com/v4/survey/2692209/surveypage/3/surveyquestion?", inputMessage.Content);

Console.WriteLine(response.Content.Headers.ContentType);
通过使用和读取缓冲区

表示HTTP实体主体和内容头的基类

通过使用和读取缓冲区

表示HTTP实体主体和内容头的基类


你在寻找内容类型还是内容响应?你在寻找内容类型还是内容响应?得到了我想要的答案,但我后来收到此异常mscorlib.dllI中发生了类型为“System.AggregateException”的未处理异常。我希望您使用的是
result
变量,而不是重新运行
content.ReadAsStringAsync()
。是的,我使用的是result变量。程序运行正常,我得到了答案,但之后我得到了异常,在这个位置有一个类型为“System.AggregateException”的未处理异常,我想是RunQuestions().Wait();看起来初始问题已满足要求,您应该打开一个新问题。祝你好运:)得到了我想要的答案,但我后来得到了此异常mscorlib.dllI中发生了类型为“System.AggregateException”的未处理异常。我希望你使用的是
result
变量,而不是重新运行
content.ReadAsStringAsync()
。是的,我使用的是result变量。程序运行正常,我得到了答案,但之后我得到了异常,在这个位置有一个类型为“System.AggregateException”的未处理异常,我想是RunQuestions().Wait();看起来初始问题已满足要求,您应该打开一个新问题。祝你好运:)