0

There are 500 pieces of data I got from excel in Listbox1. How can I post them all with Restsharp. In one sentence I have to put commas in the code in order for the item in listbox1. Example: ("hes" + "code"), ("hes" + "code"), ("hes" + "code"), ("hes" + "code"), ("hes" + "code" ), ....

Code :

public string hes; public string code;

    public AnaForm()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        var client = new RestClient("url);
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Basic idpw");
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("Cookie", "Cookie_1=value; mycode");

         for (int i = 0; i < listBox1.Items.Count; i++)
         {

                 if ((i + 1) <= listBox1.Items.Count )
                 {
                     hes = "hes_code";
                     code += listBox1.Items[i];
                     request.AddParameter("application/json", "[{\"" + hes + "\": \"" + code + "\"}]", ParameterType.RequestBody);
                 }
          }

        IRestResponse response = client.Execute(request);
        textBox1.Text = response.Content;
melih
  • 3
  • 2
  • Looks like you have CSV data (separated by commas). So in c# using : string.Join(",", array) – jdweng Jan 19 '21 at 08:19
  • I'm transferring my data from excel to listbox1. 500 pieces of data. In this code: request.AddParameter ("application / json", "[{\" "+ hes +" \ ": \" "+ code +" \ "}]", ParameterType.RequestBody); "[{\" "+ hes +" \ ": \" "+ code +" \ "},{\" "+ hes1 +" \ ": \" "+ code1 +" \ "},{\" "+ hes2 +" \ ": \" "+ code2 +" \ "},{\" "+ hes3+" \ ": \" "+ code3 +" \ "},{\" "+ hes4 +" \ ": \" "+ code4 +" \ "}...{\" "+ hes500 +" \ ": \" "+ code500 +" \ "}]" I need to send like – melih Jan 19 '21 at 09:19
  • You are converting CSV to JSON so see following : https://stackoverflow.com/questions/10824165/converting-a-csv-file-to-json-using-c-sharp/46613735 – jdweng Jan 19 '21 at 10:26
  • I'm not very good. I did not understand more than the page you sent. Can you help with the codes – melih Jan 19 '21 at 11:07
  • I'm not a JSON expert. – jdweng Jan 19 '21 at 11:37

0 Answers0