2016-01-10 35 views
8

http://support.microsoft.com/en-us/us/us/support.aspx?hl=tr http://support.microsoft.com/contactus/default.asp bu ilk ve sonra hex json yazdırırKonsolda http isteği nasıl yazdırılır

let postsEndpoint: String = "https://www.example.com/api/" 
guard let postsURL = NSURL(string: postsEndpoint) else { 
    throw APICallError.other("cannot create URL") 
} 
let postsURLRequest = NSMutableURLRequest(URL: postsURL) 
postsURLRequest.HTTPMethod = "POST" 
print(UTF8EncodedJSON) 
postsURLRequest.HTTPBody = UTF8EncodedJSON 
print(postsURLRequest) 

let config = NSURLSessionConfiguration.defaultSessionConfiguration() 
let session = NSURLSession(configuration: config) 

let task = session.dataTaskWithRequest(postsURLRequest, completionHandler: { 
    (data, response, error) in 
    //handle response 
}) 

: bana çok yardımcı olmuyor

<NSMutableURLRequest: 0x7fdae8d1dd30> { URL: https://www.ritzie.nl/api/v2 }

Bu benim kodudur. Örneğin tüm isteğimin, örneğin firefox'ta ateş böceğinde göreceğiniz gibi basılmasını istiyorum. --edit--

benim json yazdırmaya çalışıyorum değilim, netleştirmek için. Bu konuda zaten SO ile ilgili yeterli soru var. Ben tam isteği böyle bir şey çıktısı istiyorum:

POST /api/v2/ HTTP/1.1 

HTTP headers: 
Host: www.example.ocm 
Origin: http://www.example.com 
Connection: keep-alive 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/\*;q=0.8 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9 
Referer: http://www.ritzie.nl/api/test.php 
Accept-Language: en-us 
Accept-Encoding: gzip, deflate 

request body: 
data=%7B%22action%22%3A+%22vehicleRecords%22%2C%0D%0A%22token%22%3A+%22token_04e01fdc78205f0f6542bd523519e12fd3329ba9%22%2C%0D%0A%22vehicle%22%3A+%22vehicle_e5b79b2e%22%7D 

veya bu: completionHandler iç

Firebug request screenshot

+0

Eğer verilerden bir dize oluşturmak için gereken JSON metnini görmek istiyorsan bütün – Wain

+0

@Wain olduğunu lol hayır, benim bütün görmek istiyorum http isteği. 'GET/API/v2/HTTP/1.1 HTTP üst: Host: www.ritzie.nl Kabul: */* Çerez: PHPSESSID = vd61qutdll216hbs3a677fgsq4 User-Agent: KM% 20registratie% 20tabbed% Bunun gibi 20NL/1 CFNetwork/758.2.8 Darwin/15.2.0 Accept-Language: gzip Bağlantı deflate: bize tr-Kodlama Kabul – Fr4nc3sc0NL

+0

Yani başlıklarını kendiniz – Wain

cevap

0

Baskı it:

let task = session.dataTaskWithRequest(postsURLRequest, completionHandler: { 
    (data, response, error) in 
    //handle response 
    print(NSString(data: data.HTTPBody!, encoding:NSUTF8StringEncoding)!) 
}) 

o zaman işe yaramadı eğer Aşağıdakileri kullanın:

print(NSString(data: data, encoding: NSUTF8StringEncoding)) 
+0

yanıt kütüğünü yazdırıyorsunuz, bu isteğin tamamını istiyorum – Fr4nc3sc0NL

1

Bu seferki benim için çalışıyor:

let task = session.dataTaskWithRequest(postsURLRequest, completionHandler: { 
     (data, response, error) in 
     if let _data = data 
     { 
      do { 
       var jsonResult: NSDictionary 
       try jsonResult = NSJSONSerialization.JSONObjectWithData(_data, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary 
       print("AsSynchronous\(jsonResult)") 
      } 
      catch { 
       // handle error 
      } 
     } 
     else 
     { 
      print("Error: no data for request \(urlPath)") 
     } 
    }) 
-1
let task = session.dataTaskWithRequest(postsURLRequest, completionHandler: { 
    (data, response, error) in 
    //handle response 
    print(NSString(data: response.request, encoding:NSUTF8StringEncoding)!) 
}) 
+0

Yanıt nesnesi üzerinde istek özelliği yoktur. – Nate