4

I tried to access the rest api call URLSession in the swift and server side AKKA framework used. I am getting 503 error frequently. I have searched lot thing and most of result says it's server side issue. I have tested in postman and JMeter concurrent test cann't face any issue (error code 503). I hope 503 getting not because of sever side issue.

let headers = ["content-type": "application/json",
 "access-token": "3ccecc61-1fc5-4f54-88d5",
]
let parameters = [
  "s3url": "https://s3-us-west-1.amazonaws.com/image.png",
  "gender": 1,
  "userid": 22,
  "username": "sample"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://ec2.compute-1.amazonaws.com/generate-image")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()

ios response

dataTaskWithRequest HTTP status code: 503
dataTaskWithRequest HTTP response code: <NSHTTPURLResponse: 0x17043f160> { URL: http://ec2.amazonaws.com:9000/image } { status code: 503, headers {
    "Content-Length" = 105;
    "Content-Type" = "text/plain; charset=UTF-8";
    Date = "Mon, 18 Sep 2017 15:01:41 GMT";
    Server = "akka-http/10.0.0";
} }
rjdkolb
  • 10,377
  • 11
  • 69
  • 89
kathiravan
  • 41
  • 1
  • 4
  • I hope 503 getting not because of sever side issue.... You can hope but it is server issue... the status code 500 means server gave up, it could be your supplied data may have caused server to crash... – dipak Sep 18 '17 at 15:50

1 Answers1

1

Its probably a DNS issue. 503 is service unavailable503 DESC so there are a few things you can check.

  1. can you get on that machine in AWS and ensure the code is running on it. if you can remote into the machine and hit the route locally (http://localhost/genreate-image) then you can be pretty sure the issue is related to DNS.

  2. If the first option passes then I would look at your security group setup in AWS to see if traffic is being allowed on that port.

  3. Lastly I would check DNS, the url you are hitting is "http://ec2.compute-1.amazonaws.com" can you verify that if you ping or telnet to the http ports on that machine. this will make sure that DNS is giving you the right address for that name.

DLB
  • 64
  • 5
  • Thank for ur answer. let me try them then i will update. but i am not receiving any error JMeter and postman – kathiravan Sep 19 '17 at 05:55