Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.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# C-ByteArray和字符串与HTTPClient对象一起_C#_Json_Asp.net Web Api_Httpclient - Fatal编程技术网

C# C-ByteArray和字符串与HTTPClient对象一起

C# C-ByteArray和字符串与HTTPClient对象一起,c#,json,asp.net-web-api,httpclient,C#,Json,Asp.net Web Api,Httpclient,我试图攻击第三方API无法共享、保密,他们希望以下json作为输入: { PFID: “abc”, CY: 2015, AZs: [ { AZN: “AZ1”, x: <bytes>, y: <bytes>, x: <bytes> }, { AZN: “AZ2”, x: <bytes>, y: <bytes>, z: <bytes> } ] } 我正在使

我试图攻击第三方API无法共享、保密,他们希望以下json作为输入:

{ 
PFID: “abc”,
CY: 2015,
AZs: [
    { AZN: “AZ1”, 
        x: <bytes>, y: <bytes>, x: <bytes>
    },
    { AZN: “AZ2”, 
        x: <bytes>, y: <bytes>, z: <bytes>
    }
]
}
我正在使用HTTPClient向此WebAPI提交请求。以下是这方面的代码片段:

public void AddApplication(AZR request)
{
    HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(url);

             client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

        client.DefaultRequestHeaders.Add("authorization","mybearertoken");

    innerJson = Json.JsonParser.Serialize<AppZoneRequest>(request); // <=== coming perfectly till here. json returns a perfect json with in bytes flowing in a perfect hierarchy
    HttpContent content = new StringContent(innerJson, Encoding.UTF8, "application/json"); // <==== my best guess is problem is here
    HttpResponseMessage response = client.PostAsync(apiURL, content).Result;    
    return response;
}


  public class AZR
    {
        public string PFID { get; set; }
        public int CY { get; set; }
        public List<xyz> AZs { get; set; }
    }
    public class xyz
    {
        public string AZN { get; set; }
        public byte[] x { get; set; }
        public byte[] y { get; set; }
        public byte[] z { get; set; }
    }

当我发布请求时,它会向我返回状态500,这表明存在内部服务器错误。我知道不能在字符串内容中序列化字节数组,我们需要使用ByteArrayContent,如果两者都有,则使用HttpMultipartFormDataContent。但在这里,层次结构是这样的,我有string,int和一个对象数组,其中的对象包含string,byte[],byte[],byte[]。现在,我真的找不到一个方法来提交这样一个帖子请求。有什么帮助吗?

您确定他们指的是字节[]而不是base64编码的字符串吗?第一个代码块完全是从他们的文档中提取的。当然,我们已经更改了变量名。但这是他们说我们需要发送的。我愿意尝试任何东西,你认为我应该发送Base64字符串而不是字节吗?仅供参考,字节实际上是File Bytestried,不起作用。还有什么建议吗?我想你最好的办法是联系那个API提供商,问他们确切的意思。不能直接用json发送byte[]。这里只存在一个解决方案,它使用base64字符串。[如何使用bas64编码]