簡體   English   中英

RestSharp請求的錯誤消息

[英]Error message for RestSharp request

我收到此錯誤消息:

{
    "result":"failure",
    "message":"Identifier is invalid",
    "time":"2018-05-25 15:34:13",
    "type":"items"
}

CompletedOK

這將發送到SureDone API。 我不確定此錯誤消息具體指的是什么。 我要從Excel文件中提取數據,我可能使用了錯誤的內容類型? 這是我的代碼:

private void btnLoad_Click(object sender, EventArgs e)
{
    string PathConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + txtChooseFile.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
    OleDbConnection conn = new OleDbConnection(PathConn);

    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + txtLoad.Text + "$]", conn);
    DataTable dt = new DataTable();

    da.Fill(dt);

    dataGridView.DataSource = dt;

    String payload = "";
    int i = 1;

    //REST request
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    var client = new RestClient("https://api.suredone.com/v1/editor/items/add");
    var request = new RestRequest(Method.POST);
    request.AddHeader("x-auth-token", "{token}");
    request.AddHeader("x-auth-user", "{username}");
    //request.AddHeader("content-type", "application/x-www-form-urlencoded");
    request.AddHeader("Content-type", "multipart/form-data");

    foreach(DataRow row in dt.Rows)
    {
        Hashtable postData = new Hashtable();
        postData["identifier"] = "guid";
        postData["guid"] = row["sku"].ToString();
        postData["price"] = row["price"].ToString();
        postData["title"] = row["title"].ToString();
        postData["action"] = row["action"].ToString();
        postData["stock"] = row["stock"].ToString();
        postData["msrp"] = row["msrp"].ToString();
        postData["longDescription"] = row["longdescription"].ToString();
        postData["condition"] = row["condition"].ToString();
        postData["brand"] = row["brand"].ToString();
        postData["notes"] = row["notes"].ToString();

        String formBoundary = "undefined";

        foreach (DictionaryEntry entry in postData)
        {
            payload += "--" + formBoundary + "\r\n" + 
                "Content-Disposition: form-data; name=" + 
                    entry.Key.ToString() + "\r\n\r\n" + 
                    entry.Value.ToString() + "\r\n\r\n";
        }//foreach(DictionaryEntry)CLOSE

        i++; //incrementer
    }//foreach(row) CLOSE

    //REST response 
    request.AddParameter("multipart/form-data", payload, ParameterType.RequestBody);
    IRestResponse response = client.Execute(request);
    txtResponse.Text = response.Content + response.ErrorMessage + response.ResponseStatus + response.StatusCode;

    txtProducts.Text = payload;
}//button load click close 

檢查第28行:

postData["identifier"] = "guid"; 

我認為應該

postData["identifier"] = row["guid"].ToString();

並檢查下一行。 似乎很奇怪:

postData["guid"] = row["sku"].ToString();

請求和Excel文件的字段是否相同?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM