无法在C#中使用Webrequest方法上载文件

问题描述 投票:1回答:1

我正在尝试使用voxbone的rest api服务上传地址证明。但我得到一个错误:“远程服务器返回错误:(500)内部服务器错误。”当我联系技术支持团队的voxbone团队他们说我的请求没有到达那里系统....请帮我解决这个问题

 WebRequest myReq = WebRequest.Create("https://sandbox.voxbone.com/ws-voxbone/services/rest/regulation/address 
    "); 
    myReq.Method = method; 
    myReq.ContentType = "multipart/form-data; boundary= XXX"; 
    string username = xxxxxx; 
    string password = xxxxxx;

    string usernamePassword = username + ":" + password;

    UTF8Encoding enc = new UTF8Encoding();


    myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(enc.GetBytes(usernamePassword)));

    string str2 = " 
    --XXX 
    Content-ID: createRegulationAddressRequest 
    Content-Type: application/json

    { 
    "salutation" : "MR", 
    "companyName" : null, 
    "companyDescription" : null, 
    "firstName" : "rahul", 
    "lastName" : "singh", 
    "buildingNumber" : "23",     
    "identityDocumentProof" : 
    { 
    "Nationality" : "IND", 
    "identityDocumentType" : "NATIONAL_ID_CARD", 
    "identityDocumentNumber" : "jfklajfljsdfl;dslfj" , 
    "issuingAuthority" : "jkhkjhkj", 
    "issuingDate" : "2017-11-30" 
    } , 
    "extraFields" : 
    { 
    "Signatory date of birth" : "1993-01-05", 
    "Signatory place of birth" : "varanasi,India", 
    "Signatory tax code" : "dsdfsfsdf" 
    } 
    } 
    --XXX-- 
    Content-ID: proofOfIdentityDocument 
    Content-Type: application/octet-stream 
    Content-Transfer-Encoding: binary 
    Content-Disposition: file-data; name="proofOfIdentityDocument"; filename=stripe.png

    Wuppertal

    --XXX--"; 

    byte[] buffer3 = Encoding.GetEncoding("UTF-8").GetBytes(str2);

    string result = System.Convert.ToBase64String(buffer3 ); 
    Stream reqstr = myReq.GetRequestStream(); 
    reqstr.Write(data, 0, data.Length); 
    reqstr.Close();

    WebResponse wr = myReq.GetResponse(); 
    Stream receiveStream = wr.GetResponseStream(); 
    StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); 
    string content = reader.ReadToEnd();
c# webrequest
1个回答
0
投票

来自Voxbone Error codes docs

FIELD_MISSING 500缺少字段。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.