قالب وردپرس درنا توس
Home / IOS Development / javascript – Axios POST fails on iOS

javascript – Axios POST fails on iOS



I'm trying to make a simple ajax POST from domain1 to domain2 using Axios.
This is a single POST across domains, so there is no PREFLIGHT (OPTIONS) call.
The response from the application is a simple JSON string.

On Chrome, on Android, Windows and iOS (except the iPhone) this works fine.
But on the iPhone 6,7,8+ on both Safari and Chrome, I get an error in the console from the axios answer. I can see the POST request coming to the application on domain2 and a json response being sent. But this is what appears when I console.log the answer in axios.catch. There are no other details.

  Error: Network error

My POST is a multipart / form data entry with the following Inquiry headers:

  Accept: application / json, text / plain, * / *
Content type: multipart / form data; boundary = ---- WebKitFormBoundary81
kouhSK7WgyVQZ3 Origin: https: // domain1 Referer: https: // domain1 / test User Agent: Mozilla / 5.0 (iPhone; CPU iPhone OS 11_0 as Mac OS X) AppleWebKit / 604.1.38 (KHTML, as Gecko) Version / 11.0 Mobile / 15A372 Safari / 604.1

And the form data is simply four text fields

  ------ WebKitFormBoundary81kouhSK7WgyVQZ3
Content-Disposition: form data; name = "a"
12345
------ WebKitFormBoundary81kouhSK7WgyVQZ3
Content-Disposition: form data; name = "b"
asdfasf
------ WebKitFormBoundary81kouhSK7WgyVQZ3
Content-Disposition: form data; name = "c"
asdfadsf
------ WebKitFormBoundary81kouhSK7WgyVQZ3
Content-Disposition: form data; name = "d"
adfasdfa
------ WebKitFormBoundary81kouhSK7WgyVQZ3--

When POST is sent from Chrome, (or IE and Firefox) on Windows and Mac, I get the following reply headers and an HTTP 200:

  access control allow headers: Accept, Content Type, Origin, Referrer, User Agent
access control permission methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin: *
cache control: no-cache, private
content type: application / json, text / plain, * / *; charset = UTF-8
x-content-type options: nosniff
x-rate limit limit: 60
x-ratlimit remaining: 59
x-xss protection: 1

which I have explicitly specified the use of domain2 (Laravel 5.8 application – CORS headers put in middleware).

But on iPhone, both Safari and Chrome (and on Safari browser on a Mac – Chrome works on Mac) I see no answer – conole.log (error) shows (see axios code below)

  Error : Network error

And in the network tab that looks at the request / response, there are no reply headers returned and no HTTP status code. Only the request headers are displayed.

My axiocode is the following:

  axios.post (& # 39; https: // domain2 / test & # 39 ;, formData)
.then (function (response) {

console.log ("POST function of axios 1");
console.log (response);
console.log ("POST function of axios 2");
})
.capture (function (error) {
console.log ("Error in capturing axios post");
console.log (error);
console.log ("End error");
});

FormData is created using formData.append (& # 39; a, 12345) etc …

I can successfully POST to a test upload from https: // domain1 to https: // domain1 using the same axios code, so I think there are some issues with the domain2 response headers that iOS does not like and kill the answer.

I have tried to set / change all answer headers, put headlines on Axios POST, tried to use simple xhr instead of Axios etc. but to no avail … same error.

Is anyone pointing? I have googled etc … but haven't found anything that helps.
Even how to get more information from the Fault Reader on iPhone?
I debug iPhone on a Mac so you can see the console.log etc …

Many thanks


Source link