Skip to content
Advertisement

Tag: okhttp

Mocking nested retrofit api calls using MockWebServer

I am writing a junit test using okhttp3.mockwebserver for a retrofit2 rest api. The trimmed down api looks like this: The api is then injected to another class which delegates the calls thusly: I do the following in my test: Because the implementation of cancelOrder() calls api.cancelOrder() and then api.getOrders(), I added two mocked responses corresponding to each. However, looks

Could not transfer artifact com.squareup.okhttp3:mockwebserver:pom:4.9.1 from/to central (https://repo.maven.apache.org/maven2)

I have encountered a problem while importing the MockWebServer dependencies into my project Idea is showing 2 problems: Dependency ‘com.squareup.okhttp3:okhttp:4.9.1’ not found Dependency ‘com.squareup.okhttp3:mockwebserver:4.9.1’ not found And reload all maven projects results in a big “stacktrace” which generally says that it can’t resolve any of the dependencies. Running maven goal compile results in an error: Could not transfer artifact com.squareup.okhttp3:okhttp:pom:4.9.1

Update default Content-Type for multipart form-data request in Android

We are currently using okhttp3 and retrofit2 in Android to make an network api call of type POST with multipart/form-data, the api request and response are as shown below If you observe, the request header Content-Type has “multipart/form-data; boundary=xxxxxx-xxxx-xxx….” Following is the code I’m facing an issue with sending the customised request header Content-Type as “multipart/form-data; **charset=utf-8;** boundary=xxxxx-xxxxx-x…..” basically i

FATAL EXCEPTION: OkHttp Dispatcher

I’m using the OkHttp library in my android app to make web requests to a weather API. I’ve already implemented my code and I’m getting a FATAL EXCEPTION when doing the request. I’ve already added INTERNET permissions in my manifest too. MainActivity.java: Gradle: Then, here’s the exception I’m getting: I don’t know what to do at this point. I’ve read

Can’t get OkHttp’s response.body.toString() to return a string

I’m trying to get some json data using OkHttp and can’t figure out why when i try logging the response.body().toString() what i get is Results:﹕ com.squareup.okhttp.Call$RealResponseBody@41c16aa8 I don’t know what i’m doing wrong here. How do i get the response string? Answer Just in case someone bumps into the same weird thing as I have. I run my code during

Advertisement