发布多部分时,JSONObject 文本必须以字符 0 处的“{”开头
A JSONObject text must begin with '{' at character 0 when posting multipart
我正在尝试从 windows phone 在 C# 中进行多部分调用。
我正在发送与正在工作的 android 调用完全相同的 json,但是从 wp 我收到了这个响应 body:
"errorNumber":90 - JSONObject 文本必须在 "}
的字符 0 处以 '{' 开头
我发送的第一个字符是{.
为什么会这样?
这是我的代码:
public async Task postHttpClient(string serviceUrl, string requestObj)
{
Debug.WriteLine("postHttpClient");
try
{
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data");
Debug.WriteLine("requestObj: " + requestObj);
Debug.WriteLine("curly brace should be expected: " + (int)requestObj.Trim().ElementAt(0));
MultipartFormDataContent content = new MultipartFormDataContent();
var contentData = new StringContent(requestObj.Trim());
content.Add(contentData);
var responseVar = await client.PostAsync(serviceUrl, content);
responseVar.EnsureSuccessStatusCode();
Debug.WriteLine("responseVar: " + responseVar.ToString());
var body = await responseVar.Content.ReadAsStringAsync();
Debug.WriteLine("body: " + body);
}
catch (Exception e)
{
Debug.WriteLine("e: " + e.ToString());
}
}
和我的提琴手:
原始 Headers
POST/MyServer/SendActivity/HTTP/1.1
接受:/
Content-Length: 703
Accept-Encoding: 身份
Content-Type: multipart/form-data;边界="e8763d7d-a53d-4baa-a6c7-c3bc37bd52a6"
User-Agent: NativeHost
主持人:merp.techmobile.eu:8080
连接:Keep-Alive
编译指示:no-cache
文本视图选项卡
--e8763d7d-a53d-4baa-a6c7-c3bc37bd52a6
Content-Type: text/plain;字符集=utf-8
Content-Disposition: form-data
{"SendActivityRequest":{"activity":{...
通过向我的 json、
添加密钥可能会帮助别人知道我修复了它
通过更改此行:content.Add(contentData);
对此 content.Add(contentData, "request");
我正在尝试从 windows phone 在 C# 中进行多部分调用。 我正在发送与正在工作的 android 调用完全相同的 json,但是从 wp 我收到了这个响应 body:
"errorNumber":90 - JSONObject 文本必须在 "}
的字符 0 处以 '{' 开头我发送的第一个字符是{.
为什么会这样?
这是我的代码:
public async Task postHttpClient(string serviceUrl, string requestObj)
{
Debug.WriteLine("postHttpClient");
try
{
var client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "multipart/form-data");
Debug.WriteLine("requestObj: " + requestObj);
Debug.WriteLine("curly brace should be expected: " + (int)requestObj.Trim().ElementAt(0));
MultipartFormDataContent content = new MultipartFormDataContent();
var contentData = new StringContent(requestObj.Trim());
content.Add(contentData);
var responseVar = await client.PostAsync(serviceUrl, content);
responseVar.EnsureSuccessStatusCode();
Debug.WriteLine("responseVar: " + responseVar.ToString());
var body = await responseVar.Content.ReadAsStringAsync();
Debug.WriteLine("body: " + body);
}
catch (Exception e)
{
Debug.WriteLine("e: " + e.ToString());
}
}
和我的提琴手:
原始 Headers
POST/MyServer/SendActivity/HTTP/1.1 接受:/ Content-Length: 703 Accept-Encoding: 身份 Content-Type: multipart/form-data;边界="e8763d7d-a53d-4baa-a6c7-c3bc37bd52a6" User-Agent: NativeHost 主持人:merp.techmobile.eu:8080 连接:Keep-Alive 编译指示:no-cache
文本视图选项卡
--e8763d7d-a53d-4baa-a6c7-c3bc37bd52a6 Content-Type: text/plain;字符集=utf-8 Content-Disposition: form-data
{"SendActivityRequest":{"activity":{...
通过向我的 json、
添加密钥可能会帮助别人知道我修复了它通过更改此行:content.Add(contentData);
对此 content.Add(contentData, "request");