-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPBodyStream not opening. #109
Comments
Never tried that before so not sure, but it seems like you are trying to (The issue is probably not related to OHHTTPStubs btw) |
If the workaround in wiki is not working, please remove it .
|
😲 I'm not the one who wrote that in my wiki! Will check this out. |
@jeremy-w As you're the one who added that in my Wiki, could you explain how you made it work (or if you tested it at all), given that it doesn't seem to work for the people commenting in this issue? |
@AliSoftware I wrote it up only after I got it working in some project, so it's not an untested workaround. It's been a while though, so I'd have to do some digging to surface the code in question. What immediately leaps to mind on reading the original post is that It's also possible that framework changes since I used the workaround have broken it. |
Thx for the feedback @jeremy-w 👍 |
I seem to be able to check the body by serialzing the OHHTTPStubs.stubRequests(passingTest: { (request) -> Bool in
guard let httpBodyStream = request.httpBodyStream else { return false }
do {
httpBodyStream.open()
let requestBody = try JSONSerialization.jsonObject(with: httpBodyStream, options: [])
print("requestBody",requestBody)
} catch let error as NSError {
print("error: \(error.localizedDescription)")
} |
I followed the instructions here: https://github.com/AliSoftware/OHHTTPStubs/wiki/Testing-for-the-request-body-in-your-stubs#a-transparent-workaround
And when I call the following code:
I keep getting the error saying
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSJSONSerialization JSONObjectWithStream:options:error:]: stream is not open for reading'
It should be working since the stream is not nil and I have opened it, but I can't seem to get it to actual open for reading.
The text was updated successfully, but these errors were encountered: