mrmike / ok2curl Goto Github PK
View Code? Open in Web Editor NEWConvert OkHttp requests into curl logs.
License: Apache License 2.0
Convert OkHttp requests into curl logs.
License: Apache License 2.0
System.err:
Caused by: java.lang.ClassCastException: okhttp3.Headers cannot be cast to java.lang.Iterable
Because of:
okhttp3.Headers will extends Iterable until after okttp_4.x.
Maybe need add to README.
From backend I'm receiving a header like this: etag: "estoesunapruebadeetag"
the "
are part of the etag.
OkHttp when I call this endpoint again it adds this header: If-None-Match: "estoesunapruebadeetag"
.
But on curl I see this: -H "If-None-Match:"estoesunapruebadeetag""
when it should be -H "If-None-Match:\"estoesunapruebadeetag\""
. The "
should be escaped.
How can I use your library with maven?
I tried to get it from Maven Central repo:
<dependency>
<groupId>com.github.mrmike</groupId>
<artifactId>okcurl</artifactId>
<version>0.2.5</version>
</dependency>
but there's no such groupId. Going to https://repo.maven.apache.org/maven2/com/github/mrmike/ returns 404.
In an app I bridge cookies between the WebView and okhttp. This is done by setting a cookie-handler on the okhttp-client. These cookies, however, do not show up as headers in the requests that are printed.
example cookie handler & request (httpbin here simply echos the cookies it receives).
public class Ok2CurlCookieDemo {
static final String tag = "Ok2CurlCookieDemo";
private Ok2CurlCookieDemo() {
}
public static class FooBarCookieHandler extends CookieHandler {
@Override
public Map<String, List<String>> get(final URI uri, final Map<String, List<String>> requestHeaders) throws IOException {
final Map<String, List<String>> result = Maps.newHashMap();
final ArrayList<String> value = Lists.newArrayList("foo=bar; banana=rama;");
result.put("Cookie", value);
return result;
}
@Override
public void put(final URI uri, final Map<String, List<String>> responseHeaders) throws IOException {
}
}
public static void doRequest() {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCookieHandler(new FooBarCookieHandler());
Ok2Curl.set(okHttpClient);
okHttpClient
.newCall(new Request.Builder().url("http://httpbin.org/cookies").build())
.enqueue(new Callback() {
@Override
public void onFailure(final Request request, final IOException e) {
}
@Override
public void onResponse(final Response response) throws IOException {
Log.d(tag, "httpbin got cookies: " + response.body().string());
}
});
}
}
outputs:
10-16 10:39:49.350 1586-1608/? D/Ok2Curl: curl -X GET http://httpbin.org/cookies
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: httpbin got cookies: {
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: "cookies": {
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: "banana": "rama",
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: "foo": "bar"
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: }
10-16 10:39:49.556 1586-1608/? D/Ok2CurlCookieDemo: }
In case request contains Authorization header of Basic type, e.g.,
Authorizaton: Basic bWFjaWVrOnRham5laGFzbG8xMjM=
would it be possible to have the following
curl -u maciej:tajnehaslo123 ...
?
In readme there is reference to 0.2.1 but 0.2.1 is not release
JFrog announced yesterday that Bintray and JCenter repositories will be closed by May 1st.
You use JCenter to distribute your artifacts.
Are you planning to migrate to MavenCentral?
My request is having two headers of the same name:
Cookie: JSESSIONID=....
Cookie: SOMETOKEN=....; OTHERTOKEN=....
This is correct with respect to HTTP protocol. However, CurlBuilder
will take only the last header, because it is using a map with unique keys for header names:
public CurlBuilder(Request request, long limit) {
...
final Headers headers = request.headers();
for (int i = 0; i < headers.size(); i++) {
\\ MG: If there was already a header with same name it will be overwritten here
this.headers.put(headers.name(i), headers.value(i));
}
}
I'm not able to sync gradle.
Error:Dependency com.github.mrmike:ok2curl:0.2.0 on project app resolves to an APK archive which is not supported as a compilation dependency.
I just got this error:
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: Process: my.package.name, PID: 1889
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.squareup.okhttp.MediaType.toString()' on a null object reference
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.moczul.ok2curl.CurlBuilder.<init>(CurlBuilder.java:35)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.moczul.ok2curl.CurlInterceptor.intercept(CurlInterceptor.java:31)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.squareup.okhttp.Call.access$100(Call.java:34)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-13 12:08:27.317 1889-1912/? E/AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
I used OkHttp Version 2.5 and Ok2Curl 0.0.2.
Our corporate policy accept artifacts from Maven Central only.
Would there be a chance to have this artifact in Maven Central repo as well?
Doesn't seem to be available at the moment. Publishing would be helpful when using ok2curl as a library and debugging.
https://jitpack.io/com/github/mrmike/ok2curl/0.2.2/ok2curl-0.2.2-sources.jar
Nice library BTW
IntentService
and this class is deprecatedFor the following HTTP Request:
POST https://iamakamai.sqaextranet.akamai.com/ids-sso-config/restricted/idp/reminders http/1.1
Content-Type: application/x-www-form-urlencoded
INFO: Content-Length: 54
when=2017-09-26T14%3A20%3A19.425%2B02%3A00&force=false
Ok2Curl logs invalid curl command:
Ok2Curl: curl -X POST -H "Content-Type:application/x-www-form-urlencoded" -H "Content-Length:54" -H "Host:" -H "Accept-Encoding:gzip" -H "User-Agent:okhttp/3.8.0" -d 'when=2017-09-26T14%3A17%3A57.823%2B02%3A00&force=false' https://server.com/reminders
It is invalid because the HTTP request body under "-d" is already URL encoded. It should not be, because curl will encode it anyway.
Hi and thanks for the lib,
I'm using this lib in my project to have HTTP calls logged and be able to reproduce them and import them in Postman. It works great !
But it's quite hard to find the call we are looking for because every request log start with the same text :
curl -X GET -H "Authorization:Bearer <a very looonnngg token>" -H "<some more headers>: <some more headers values>" "https://<the url we are looking for>"
So we are still using a "standard" OkHttp logger to get the URL readable easily.
Would it be possible to change the order of arguments in the curl command to :
Ex :
curl -X GET "https://example.com/endpoint" -d "a body" -H "header1: foo" -H "header2: bar"
as described in README,
added it to dependencies
compile "com.github.mrmike:Ok2Curl:0.4.5"
jcenter() is there in the repository list and also in the buildScript list
When I'm using OkHttp with a NetworkInterector that has a SSLSocketFactory factory that skips the SSL certificate validation and the hostname verification, it doesn't add the "--insecure" flag to the Curl command.
You can see an example on this StackOverflow question: http://stackoverflow.com/questions/25509296/trusting-all-certificates-with-okhttp
after upgrading from v0.2.3 to v0.2.4
...
:app:transformClassesWithDexForLiveDebug
Dex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:761)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:727)
at com.android.dx.command.dexer.Main.access$1200(Main.java:87)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1655)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:681)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:578)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:315)
at com.android.dx.command.dexer.Main.run(Main.java:286)
at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:52)
at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1511)
at com.android.builder.core.AndroidBuilder$2.call(AndroidBuilder.java:1507)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:773)
at com.android.dx.command.dexer.Main.access$1600(Main.java:87)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1694)
at com.android.dx.command.dexer.Main.processClass(Main.java:758)
... 17 more
1 error; aborting
:app:transformClassesWithDexForLiveDebug FAILED
I have only one module (android application)
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.