Comments (14)
Hi had, what would you want the body to be? Raw bytes? Fields? (Which do get encoded as a string, bit we could certainly add functions to make that easier.)
from http.fs.
Not always string, sometimes raw bytes like here https://github.com/SuaveIO/suave/blob/master/src/Suave/Web.fs#L216
from http.fs.
Sorry, haf not 'had' - autocorrect user error!
Should be doable, I'll try and have a look this weekend.
from http.fs.
OK, I've put this on github, there's now a withBodyBytes function.
The way I've implemented it is a (slightly) breaking change to the API - do you think you'd be able to have a look and see if it meets your needs, before I make a NuGet from it?
from http.fs.
Yes, sure - but perhaps you could see if the API matches; the change I'd need is to make these lines: https://github.com/SuaveIO/suave/blob/master/src/Suave.Testing/Testing.fs#L123-L190 work with Http.fs - and as a side-effect you would test almost the full implementation of Http.fs.
from http.fs.
I'll give it a look if I get the chance - having problems getting the build system working on my work PC. One thing is the timeout, which there's currently no way to set with Http.fs, but would be easy to add.
from http.fs.
Hi,
Also, would be nice with a key-value list. Body if often used to make Post requests on forms with correct Content-Type.
Mostly, it is application/x-www-form-urlencoded, but there may be other
text/plain
multipart/form-data
application/json
Something like:
let request =
createRequest Post "http://somesite.com"
|> withBodyItem {name="firstName"; value="John"}
|> withBodyItem {name="lastName"; value="Doe"}
|> withHeader (ContentType "application/x-www-form-urlencoded")
from http.fs.
Hi @Muhomorik, yes that would be pretty easy to add. I'm not sure about the name, but I can't think of a better one and it matches 'withQueryStringItem'. I'd be tempted to default the content type to x-www-form-urlencoded, but that would be confusing if someone had set the content type earlier, and there might be situations where people don't want to set it. Perhaps best just let the user set it as per your example.
If you want to have a crack at it and send me a PR go for it, otherwise I'll add it when I can, won't be for at least a week or so though.
from http.fs.
@relentless Not setting content type sends request anyway, so maybe a good idea to leave to the user.
I am afraid I am quite new to F# programming and not right there to send PR yet.
from http.fs.
Would be great to also have an interface for adding files to the request, beyond just having a body full of bytes. Otherwise I'd have to write the file encoding myself, as well as the boundary in the form.
from http.fs.
Like so http://code.activestate.com/recipes/578668-encode-multipart-form-data-for-uploading-files-via/
from http.fs.
I've browsed the code a bit, and I'm not sure it's a good idea to flush the body when you use setBody
and setBodyBytes
.
Would be better to have a ByteBody and a StreamBody as possible values to set to your Request object, so that I can re-use the request object and also be very specific about when I want the data to be 'used'/stream disposed.
from http.fs.
Something like this
let body =
// http://ftp.isi.edu/in-notes/rfc2046.txt
String.concat "\r\n" [
yield "--" + boundary
yield sprintf "Content-Disposition: form-data; name=\"file\"; filename=\"%s\""
(escapeQuotes file.name)
yield sprintf "Content-Type: %s" (file.guessMime ())
use ms = new MemoryStream()
stream.CopyTo ms
yield ""
yield Convert.ToBase64String (ms.ToArray())
yield "--" + boundary + "--"
]
from http.fs.
Closing in favour of #65 and related child-issues.
from http.fs.
Related Issues (20)
- Resource temporarily unavailable HOT 3
- Update FAQ to indicate using HttpClient not HttpWebRequest/Response under the hood HOT 1
- Question re. GZip and Decompression HOT 1
- Downloading of large files gets "Failed to get response" exception after 100 seconds? HOT 2
- How would I determine content-length, content-type, etc without actually downloading the file? HOT 4
- README corrections
- content-type header is not sent with GET request HOT 10
- Custom http method HOT 1
- Send body from stream HOT 1
- Setting Content Headers in requests HOT 2
- How to ignore TLS Certificate errors HOT 1
- Body not sent with DELETE request HOT 2
- Add request header If-Unmodified-Since HOT 2
- Exception thrown from Hopac HOT 5
- Can't get proxy working HOT 3
- How to enable TCP Keep Alive HOT 1
- Latest package version is compiled with .NET Core-based String.split overload making it incompatible with .NET Framework and .NET Standard 2.0 HOT 6
- Docs outdated? HOT 1
- RobiniaDocs API Explorer
- Parasitic code warning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http.fs.