gpt4 book ai didi

ios - 将图像转换为Base64编码(状态码为500)

转载 作者:搜寻专家 更新时间:2023-11-01 07:03:47 24 4
gpt4 key购买 nike

<分区>

当我想在服务器上发送一些数据时,我遇到了一些错误。这个问题是当我将图像转换为 Base64 代码时,它会产生一些问题。请帮我解决这个问题。数据格式不正确,状态代码为 500。我不知道如何解决这个问题。

错误:

<NSHTTPURLResponse: 0x1c043c2c0> { URL: http://192.168.1.58/api/visitor/store } { Status Code: 500, Headers {

"Cache-Control" = (

"no-cache, private"
);
Connection = (
close
);

"Content-Type" = (

"text/html; charset=UTF-8"

);

Date = (
"Mon, 19 Mar 2018 05:11:06 GMT"
);
Server = (

"Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/7.1.1"

);

"Transfer-Encoding" = (

Identity

);

Vary = (

Authorization

);

"X-Powered-By" = (
"PHP/7.1.1"
);

"X-RateLimit-Limit" = (

60

);
"X-RateLimit-Remaining" = (
59
);
} }

The data couldn’t be read because it isn’t in the correct format.

我的代码是:

func apiToSaveData(strURL: String)

{

let myURL = URL(string: strURL)



let request = NSMutableURLRequest(url: myURL!)

request.httpMethod = "POST"

request.setValue("application/json", forHTTPHeaderField: "Accept")

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



let token = "Bearer " + strToken

request.setValue(token, forHTTPHeaderField: "Authorization")



var postString: [String : String] = ["" : ""]

if let navController = self.navigationController, navController.viewControllers.count >= 2

{

//Comes from After VerifyOTP after Returning Screen

let viewController = navController.viewControllers[navController.viewControllers.count - 2]

if viewController.restorationIdentifier == "VerifyOTP"

{

postString = ["image": strEncodedImg, "name": tfName.text!, "phone": tfMobile.text!, "email": tfEmail.text!, "otp": strOTP]

}



else if viewController.restorationIdentifier == "VisitorVC"

{

let imgObj = otlBtnTakeImage.imageView?.image

let imgData: Data = UIImagePNGRepresentation(imgObj!)!

let strEncodedImg1 = imgData.base64EncodedString()

print("ENcodedImage: \(strEncodedImg1)")

postString = ["image": strEncodedImg1, "name": tfName.text!, "phone": tfMobile.text!, "email": tfEmail.text!]
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com