Как я могу отправить CSV файл через REST API? [закрыто]

Вы можете использовать React.Children для итерации над дочерними элементами, а затем клонировать каждый элемент новыми реквизитами (неглубоким объединением), используя React.cloneElement , например:

const Child = ({ doSomething, value }) => (
  
doSomething(value)}>Click Me
); class Parent extends React.PureComponent { doSomething = (value) => { console.log('doSomething called by child with value:', value); } render() { const { children } = this.props; const childrenWithProps = React.Children.map(children, child => React.cloneElement(child, { doSomething: this.doSomething })); return
{childrenWithProps}
} }; ReactDOM.render( , document.getElementById('container') );

Fiddle: https://jsfiddle.net/2q294y43/2/

-3
задан Juanka . 13 July 2018 в 23:23
поделиться

1 ответ

это решение работает для меня.

// получить токен

 public string getToken(String sURL, String sUserName, String sPassword)
 {  String access_token = "";
     string clientId = "client";
     string clientSecret = "secret";
     string credentials = String.Format("{0}:{1}", clientId, clientSecret);
     RestClient restClient = new RestClient(sURL);
     RestRequest restRequest = new RestRequest("/oauth/token");
     restRequest.RequestFormat = DataFormat.Json;
     restRequest.Method = Method.POST;
     restRequest.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
     restRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
     restRequest.AddHeader("Accept", "application/json");
     restRequest.AddParameter("grant_type", "password");
     restRequest.AddParameter("username", sUserName);
     restRequest.AddParameter("password", sPassword);
     try {
         var response = restClient.Execute(restRequest);
         if (response.StatusCode == HttpStatusCode.BadRequest){
             dynamic objError = new ExpandoObject();
             objError = JsonConvert.DeserializeObject(response.Content);
             access_token = "";
             var error = objError.invalid_grant;
             var error_description = objError.error_description;
             MessageBox.Show(error + " - " + error_description, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK){
             dynamic objRpta = new ExpandoObject();
             objRpta = JsonConvert.DeserializeObject(response.Content);
             access_token = objRpta.access_token;
             String token_type = objRpta.token_type;
             int expires_in = objRpta.expires_in;
         }
     }
     catch(IOException e){
         MessageBox.Show(e.ToString(), "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     return access_token;
}

//send CSV
public string sendDocumentoCSV(String strAccesoToken, String strRutaDocumento, String strURL)
{
    String strTicket = "";
    String code = "";
    RestClient restClient = new RestClient(strURL);
    RestRequest restRequest = new RestRequest("/v1/document");
    restRequest.RequestFormat = DataFormat.Json;
    restRequest.Method = Method.POST;

    restRequest.AddHeader("Authorization", "Bearer " + strAccesoToken);
    restRequest.AddHeader("Content-Type", "multipart/form-data");
    restRequest.AddHeader("Accept", "application/json");

    restRequest.AddFile("file", strRutaDocumento);

    var response = restClient.Execute(restRequest);

    dynamic objRptaTicket = new ExpandoObject();
    objRptaTicket = JsonConvert.DeserializeObject(response.Content);

    if (response.StatusCode == HttpStatusCode.OK){ 
        code = objRptaTicket.code;
        strTicket = objRptaTicket.description;
    }
    else{
        strEnvioDocCode = objRptaTicket.code;
        strEnvioDocTicket = objRptaTicket.description;
        MessageBox.Show(strEnvioDocCode + " " + strEnvioDocTicket, "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

    return strTicket;
}
0
ответ дан Juanka . 17 August 2018 в 12:05
поделиться
Другие вопросы по тегам:

Похожие вопросы: