http icon indicating copy to clipboard operation
http copied to clipboard

Support string responses

Open Wahsner opened this issue 4 years ago • 3 comments

Describe the bug EDIT: It has also become apparent when doing a GET request and returns a stringified json object on iOS it fails to parse. and instead errors, below is an example which id expect it to be able to handle.

"{\"ColumnDefinition\":{\"RecordNumber\":{\"ColumnType\":\"\",\"IsStatusField\":false,\"IsVisible\":false,\"TranslatedColumnName\":\"\"},\"ItemNumber\":{\"ColumnType\":\"text\",\"IsStatusField\":false,\"IsVisible\":true,\"TranslatedColumnName\":\"Item Number\"},\"Description\":{\"ColumnType\":\"text\",\"IsStatusField\":false,\"IsVisible\":true,\"TranslatedColumnName\":\"Description\"}},\"DataSource\":[{\"RowNumber\":\"1\",\"RecordNumber\":\"1,190\",\"ItemNumber\":\"000001\",\"Description\":\"\"}],\"RowCount\":1}"

When sending a put/post request with a content type of application/json, it terminates the app due to an unhandled exception error if the data is a non-object value eg string.

CoreFoundation __exceptionPreprocess
libobjc.A.dylib objc_exception_throw
Foundation +[NSJSONSerialization dataWithJSONObject:options:error:]
CapacitorCommunityHttp 0x0000000101468000 + 33396
CapacitorCommunityHttp 0x0000000101468000 + 42956
CapacitorCommunityHttp 0x0000000101468000 + 44788
CapacitorCommunityHttp 0x0000000101468000 + 87648
CapacitorCommunityHttp 0x0000000101468000 + 120732
CapacitorCommunityHttp 0x0000000101468000 + 122024
CapacitorCommunityHttp 0x0000000101468000 + 122088
Capacitor 0x0000000101190000 + 85168
Capacitor 0x0000000101190000 + 43204
libdispatch.dylib
_dispatch_call_block_and_release

Based on

To Reproduce

  private static async request(url: string) {
  const httpOptions: HttpOptions = {
      headers: {
        'Content-Type': 'application/json'
      },
      method: 'PUT'
      url: url
      data: "123456"
    };
    return await Http.request(httpOptions);
  }

I have tried both data: '"123456"' and data: "123456" and it is the same result, app termination. Edit: This might be related to #172 but not sure. I have noticed if i remove the content type json for a string request, no data is sent.

Expected behavior To be able to send a request without the app being terminated due to an unhandled exception error. To be able to send a content type request with a non-object data value

Smartphone

  • Device: iPhone 11 Pro Max
  • OS: iOS 15.0.2

Additional context Based on history, this was fixed in #141 and released in 1.1.0

Wahsner avatar Oct 27 '21 16:10 Wahsner

This plugin isnt maintained and in its current state, in my opinion, isnt fit for purpose and issues arent being addressed - It doesnt handle JSON on iOS and/or Android. Appears to work fine on Web.

I guess we'll all have to hope out for #180

Ive found another bug - However, I think this might just be because it cannot handle JSON:

Setting the responseType doesnt do anything if the responce request headers content-type includes 'application/json'. This is because it is at the top of the IF ELSE statement. If you move it to be the last in the IF ELSE it'll resolve this issue. But at the same time I dont understand why it has been done this way. And, annoyingly, I dont know much about swift.

I will, regretabily, be changing back to angular http.

Wahsner avatar Nov 05 '21 09:11 Wahsner

The plugin is indeed still maintained, I just don't have much time to work on it nowadays.

This was fixed in a recent release with #196

thomasvidas avatar Nov 13 '21 18:11 thomasvidas

Misread the issue, reopening

thomasvidas avatar Nov 13 '21 18:11 thomasvidas