3lvis / Networking

Swift HTTP Networking with stubbing and caching support
MIT License
1.36k stars 112 forks source link

HttpBody attachement #198

Closed ThabreshVivid closed 7 years ago

ThabreshVivid commented 7 years ago

How can I add this lines ?

let values = ["emailID": "info@info.com"] request.httpBody = try! JSONSerialization.data(withJSONObject: values)

3lvis commented 7 years ago

@ThabreshVivid If I understand correctly it should be something like:

let networking = Networking(baseURL: "http://httpbin.org")
networking.post("/post", parameters: ["emailID" : "info@info.com"]) { result in

}

Networking would automatically convert the parameters to JSON.

ThabreshVivid commented 7 years ago

screen shot 2017-03-17 at 5 29 09 pm

@3lvis here the 7th line I got the error. how to resolve this ?

3lvis commented 7 years ago

@ThabreshVivid it's parts and needs an array of FormDataPart.

So change it to

networking.post("DriverPhotoUpload", parts: [part]) { result in
ThabreshVivid commented 7 years ago

@3lvis How can I set the content type ??

like this, networking.post("DriverPhotoUpload", parameterType: .custom("multipart/form-data"), parameters: imageData) { result in

3lvis commented 7 years ago

The content-type is automatically set for you, since you're using the parts method, it knows you want "multipart/form-data".

3lvis commented 7 years ago

There's a simple example here.

https://github.com/3lvis/Networking/blob/master/Tests/POSTTests.swift#L116-L151

ThabreshVivid commented 7 years ago

@3lvis thanks its working too good :)