[Gambas-bugtracker] Bug #2477: Memory-Access-Error on HttpClient

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Wed Feb 9 16:34:15 CET 2022


http://gambaswiki.org/bugtracker/edit?object=BUG.2477&from=L21haW4-

Comment #2 by André ROTHE:

Here is a method of my class code:

Const MEDIA_TYPE As String = "application/vnd.de.phosco.bookmonkey.Book.v1+json"
Const ERROR_TYPE As String = "application/vnd.de.phosco.Error.v1+json"

Private webClient As New HttpClient As "webClient"

Public Sub persist(book As Book)

   Dim jsonBook As JSONCollection

   jsonBook = New JSONCollection
   jsonBook.Add(book.getId(), "id")
   jsonBook.Add(book.getTitle(), "mainTitle")
   jsonBook.Add(book.getIsbn(), "isbn")
   jsonBook.Add(book.getRating(), "rating")
   jsonBook.Add(book.getDescription(), "description")
   jsonBook.Add(Format$(book.getPublishedDate(), "yyyy-mm-dd"), "published")

   Dim headers As String[]
   headers = New String[1]

   headers.Add("Accept: " & MEDIA_TYPE & ", " & ERROR_TYPE)

   If (book.getId() = Null) Then

      With webClient
         .URL = BookMonkey.serviceDocument.getHref("books")
         .TimeOut = 30
         .Async = True
         .Post(MEDIA_TYPE, JSON.Encode(jsonBook), headers)
      End With

   Else

      With webClient
         .URL = book.getId()
         .TimeOut = 30
         .Async = True
         .Put(MEDIA_TYPE, JSON.Encode(jsonBook), headers)
      End With

   Endif

End

Both, POST and PUT, don't  work.




More information about the Bugtracker mailing list