打印HTTP请求正文

时间:2017-12-12 09:30:51

标签: ios swift httprequest

我想打印我的request.httpBody发送。

在后端,他们说他们没有收到,所以我想打印并在我的控制台中看到发送的内容。

当我打印(request.httpBody)时我得到了字节

我的代码

    let param = "AppId=\(Config.AppID)&uuid=\(Config.uuid)&file=\("file")&id=\(ID)"

    var requestBodyData = (dataString as NSString).data(using: String.Encoding.utf8.rawValue)
    requestBodyData?.append(param.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!)

    do {
    request.httpBody = requestBodyData
    } catch let error {
        print(error.localizedDescription)
    }

 //How to print this request.httpBody ? 
  // Make an asynchronous call so as not to hold up other processes.
    URLSession.shared.dataTask(with: request) { data, response, error in

        // get main queue to communicate back to user
        DispatchQueue.main.async(execute: {

            if error == nil {

                do {
                    // json containes $returnArray from php
                    let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary


               }
                )}

0 个答案:

没有答案