美文网首页
Swift请求body体为JSON是的方法

Swift请求body体为JSON是的方法

作者: 流老湿 | 来源:发表于2023-11-15 16:05 被阅读0次

            let urlString: String = ""

            varrequest =URLRequest(url:URL(string: urlString)!)

            request.httpMethod="POST"

            request.setValue("application/json", forHTTPHeaderField: "Content-Type")

            request.httpBody=try!JSONSerialization.data(withJSONObject: parameter)

            AF.request(request)

                .responseJSON{ responsein

                    switchresponse.result{

                    case.failure(leterror):

                        print(error)

                        ifletdata = response.data,letresponseString =String(data: data,encoding: .utf8) {

                            print(responseString)

                        }

                    case.success(letresponseObject):

                        print(responseObject)

                    }

            }

相关文章

网友评论

      本文标题:Swift请求body体为JSON是的方法

      本文链接:https://www.haomeiwen.com/subject/hpwswdtx.html