why putasync and deletasync dont work

shaghayeghshaghayegh USMember ✭✭
edited September 2018 in General

i use this code but dont work and no error

       `b=id.bazdid + 1;

          string <tables> t= new <tables>
                 {
             bazdid = b;
       }
       var httpClient = new HttpClient();

        var json = JsonConvert.SerializeObject(t);

        HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json");

        string url = $"http://www.aashuraian.ir/api/myTable/"; 
        //httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        var requestUrl = new Uri(string.Format(url, id.Id));

        var  response = await httpClient.PutAsync(requestUrl, httpContent);`

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I always use SendAsync and set HttpRequestMessage with HttpMethod.Put

    this is a sample

        public async Task<ChiusuraOrdineResponse> ChiusuraOrdineAsync(Login login, long idOrdine)
        {
    
            var request = new HttpRequestMessage(HttpMethod.Put, createUrl(CHIUSURA_ORDINE_URL, true));
            ChiusuraOrdineRequest chiusuraOrdineRequest = new ChiusuraOrdineRequest(idOrdine);
            request.Content = createStringContent(chiusuraOrdineRequest);
    
            _httpClient.DefaultRequestHeaders.Authorization = authenticationHeaderValue(login.token_type, login.access_token);
    
            return await readStreamAndDeserialize<ChiusuraOrdineResponse>(await _httpClient.SendAsync(request));
        }
    
    
    
        StringContent createStringContent(object oggetto)
        {
            return new StringContent(JsonConvert.SerializeObject(oggetto), Encoding.UTF8, "application/json");
        }
    
  • shaghayeghshaghayegh USMember ✭✭
    I think this problem from url.
  • shaghayeghshaghayegh USMember ✭✭

    what is value in
    var json = JsonConvert.SerializeObject(object value); ?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Oggetto is your class you have to put. The code serialize the class so you can set the content of the request
  • shaghayeghshaghayegh USMember ✭✭
    I want to update one parameter of class
  • shaghayeghshaghayegh USMember ✭✭

    No one has a comment؟

Sign In or Register to comment.