Closed robert1993 closed 4 years ago
@robert1993 Hi Robert! This error message takes place when a server-side script does not return a valid JSON model. Most likely, there is an error that takes place in PHP script and it sends back an error description plain text rather than a JSON model that Swift script expects. Try sending this HTTP request with a Postman HTTP client or in your Swift script convert the response data to String to see what came back from the PHP script.
Hi Sergey! Thank you for your quick respons. When I post something with Postmen to my webservice it returns valid json:
{
"uid": "128"
}
With the UID which I want to use in the swift code. I'm looking at it for hours now but pretty lost in the wood ;)
@robert1993 try making your PHP script return this JSON:
{\"uid\":\"128\"}
Will it work?
Too bad, Tried both {\"uid\":\"148\"} as [{\"uid\":\"148\"}]
Have you tried with the backslashes to escape the double quotes?
{\"uid\":\"128\"}
O sorry, yes tried that as well, copied the wrong return :)
The app displays this error message when I try it:
` self.removeActivityIndicator(activityIndicator: myActivityIndicator)
// Display an Alert dialog with a friendly error message
self.displayMessage(userMessage: "Could not successfully perform this request. Please try again later ofzo 2")
print(error)`
In your Swift code, try converting the received Data object to String and then printing it:
let str = String(decoding: data, as: UTF8.self) print(str)
what will it print?
Add this code right before, converting data to NSDictionary.
Aah, it does. It prints: ' <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@******* to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
`
This is the output of print(postString)
["firstName": "test", "userPassword": "test", "UID": "", "lastName": "test", "userName": "test"]
But that seems oke to me? It is the wrong order though, and also different from the code order...
Once again thank you so much for spending your time helping me !
No, but it also returns a 500 error. All together the returned String is not a valid JSON. There is an issue with the PHP script. In your earlier message, you have mentioned that PHP states:
" Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. "
Do you see this error in a log file? Do you know what are those internal redirects? Why are there so many redirects?
Damn me! instead of the url api/users/create.php it had tot be api/user/create.php So sorry for bothering you, but now it works like a charm !
Had to remove the backlashes btw ;)
Great, 👍🙂 I am glad it started working now!
Hmm still a minor issue. It's only inserting the UID in the db. But I guess I have to have a look at my PHP script for that :)
Now I can proceed with your swift tutorial 👍
Hi!
First of all, thank you very much for the great content you make!
I had to write a php json web service to be able to run in on my server. but it gives me the following error which I don't understand:
Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
PHP states: [Tue Mar 31 17:05:18.146020 2020] [core:error] [pid 864871:tid 140039761164032] [client 94.210.205.184:49849] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
Can you help ? signupviewcontroller.swift:
` import UIKit
class SignUpViewController: UIViewController {
`