{"id":38732,"date":"2016-06-29T15:00:07","date_gmt":"2016-06-29T12:00:07","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=38732"},"modified":"2023-11-09T15:22:48","modified_gmt":"2023-11-09T13:22:48","slug":"android-http-get-post-example-okhttp","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/","title":{"rendered":"Android Http Get and Post Example with OkHttp"},"content":{"rendered":"<p>In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the OkHTTP 3.0 library, where OkHTTP is an Open Source project designed to be an efficient HTTP client. The usage of this library is very simple and if you are using Gradle as build system you can simply add a dependency to your project<\/p>\n<p>For this example we are using the following tools in a Windows 64-bit or an OS X platform:<\/p>\n<ul>\n<li>JDK 1.7<\/li>\n<li>Android Studio 2.1.2<\/li>\n<li>Android SDK 5.1<\/li>\n<\/ul>\n<p>Let\u2019s take a closer look:<br \/>\n<span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:515,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16777215},&quot;12&quot;:0}\">[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/span><\/p>\n<h2>1. Create a New Android Studio Project<\/h2>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<p>Open Android Studio and choose \u201cStart a new Android Studio Project\u201d in the welcome screen.<\/p>\n<p><figure id=\"attachment_27646\" aria-describedby=\"caption-attachment-27646\" style=\"width: 797px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs1.png\"><img decoding=\"async\" class=\"size-full wp-image-27646\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs1.png\" alt=\"\u201cWelcome to Android Studio\u201d screen. Choose \u201cStart a new Android Studio Project\u201d.\" width=\"797\" height=\"601\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs1.png 797w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs1-300x226.png 300w\" sizes=\"(max-width: 797px) 100vw, 797px\" \/><\/a><figcaption id=\"caption-attachment-27646\" class=\"wp-caption-text\">\u201cWelcome to Android Studio\u201d screen. Choose \u201cStart a new Android Studio Project\u201d.<\/figcaption><\/figure><\/p>\n<p>Specify the name of the application, the project and the package.<\/p>\n<p><figure id=\"attachment_38734\" aria-describedby=\"caption-attachment-38734\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp1.png\"><img decoding=\"async\" class=\"size-full wp-image-38734\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp1.png\" alt=\"\u201cConfigure your new project\u201d screen. Add your application name and the projects package name.\" width=\"800\" height=\"520\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp1.png 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp1-300x195.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp1-768x499.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-38734\" class=\"wp-caption-text\">\u201cConfigure your new project\u201d screen. Add your application name and the projects package name.<\/figcaption><\/figure><\/p>\n<p>In the next window, select the form factors your app will run on.<\/p>\n<p><figure id=\"attachment_27648\" aria-describedby=\"caption-attachment-27648\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs3.png\"><img decoding=\"async\" class=\"size-full wp-image-27648\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs3.png\" alt=\"\u201cTarget Android Devices\u201d screen.\" width=\"800\" height=\"512\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs3.png 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioexs3-300x192.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-27648\" class=\"wp-caption-text\">\u201cTarget Android Devices\u201d screen.<\/figcaption><\/figure><\/p>\n<p>In the next window you should choose to \u201cAdd an activity to Mobile\u201d. In our example, we will choose to create a project with no activity, so choose: \u201cAdd no activity\u201d.<\/p>\n<p><figure id=\"attachment_27650\" aria-describedby=\"caption-attachment-27650\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioex4.png\"><img decoding=\"async\" class=\"size-full wp-image-27650\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioex4.png\" alt=\"\u201cAdd an activity to Mobile\u201d. Choose: \u201cAdd no activity\u201d.\" width=\"800\" height=\"512\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioex4.png 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/10\/androidstudioex4-300x192.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-27650\" class=\"wp-caption-text\">\u201cAdd an activity to Mobile\u201d. Choose: \u201cAdd no activity\u201d.<\/figcaption><\/figure><\/p>\n<p>Now press finish, and our project has just been created!<\/p>\n<h2>2. Create the layout of the project<\/h2>\n<p>Add a new xml file inside <code>\/res\/layout<\/code> folder, with name <code>main.xml<\/code>. We should have <code>\/layout\/main.xml<\/code> file and paste the code below.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><em><span style=\"text-decoration: underline;\">main.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\"&gt;\n\n    &lt;FrameLayout\n        android:layout_width=\"250dp\"\n        android:layout_height=\"50dp\"\n        android:layout_gravity=\"center\"\n        android:layout_marginTop=\"40dp\"\n        android:background=\"#454545\"\n        android:onClick=\"makeGetRequest\"&gt;\n\n        &lt;TextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center\"\n            android:text=\"Make Get Request\"\n            android:textColor=\"#ffffff\" \/&gt;\n    &lt;\/FrameLayout&gt;\n\n    &lt;FrameLayout\n        android:layout_width=\"250dp\"\n        android:layout_height=\"50dp\"\n        android:layout_gravity=\"center\"\n        android:layout_marginTop=\"20dp\"\n        android:background=\"#454545\"\n        android:onClick=\"makePostRequest\"&gt;\n\n        &lt;TextView\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center\"\n            android:text=\"Make Post Request\"\n            android:textColor=\"#ffffff\" \/&gt;\n    &lt;\/FrameLayout&gt;\n&lt;\/LinearLayout&gt;\n<\/pre>\n<h2>3. Creating the source code of the AndroidHttpPostGetActivity Activity<\/h2>\n<p>Add a new Java class inside <code>src\/com.javacodegeeks.com.javacodegeeks.androidhttppostgetexample\/<\/code> so that we are going to have the <code>src\/com.javacodegeeks.com.javacodegeeks.androidhttppostgetexample\/AndroidHttpPostGetActivity.java<\/code> file and paste the code below.<\/p>\n<p><em><span style=\"text-decoration: underline;\">AndroidHttpPostGetActivity.java<\/span><\/em><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.androidhttppostgetexample;\n\nimport java.io.IOException;\n\nimport android.app.Activity;\nimport android.os.AsyncTask;\nimport android.os.Bundle;\nimport android.view.View;\n\nimport com.javacodegeeks.R;\n\nimport okhttp3.MediaType;\nimport okhttp3.OkHttpClient;\nimport okhttp3.Request;\nimport okhttp3.RequestBody;\nimport okhttp3.Response;\n\npublic class AndroidHttpPostGetActivity extends Activity {\n    OkHttpClient client;\n    MediaType JSON;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.main);\n\n        client = new OkHttpClient();\n        JSON = MediaType.parse(\"application\/json; charset=utf-8\");\n    }\n\n    public void makeGetRequest(View v) throws IOException {\n        GetTask task = new GetTask();\n        task.execute();\n    }\n\n    public class GetTask extends AsyncTask {\n        private Exception exception;\n\n        protected String doInBackground(String... urls) {\n            try {\n                String getResponse = get(\"https:\/\/publicobject.com\/helloworld.txt\");\n                return getResponse;\n            } catch (Exception e) {\n                this.exception = e;\n                return null;\n            }\n        }\n\n        protected void onPostExecute(String getResponse) {\n            System.out.println(getResponse);\n        }\n\n        public String get(String url) throws IOException {\n            Request request = new Request.Builder()\n                    .url(url)\n                    .build();\n\n            Response response = client.newCall(request).execute();\n            return response.body().string();\n        }\n    }\n\n    public void makePostRequest(View v) throws IOException {\n        PostTask task = new PostTask();\n        task.execute();\n    }\n\n    public class PostTask extends AsyncTask {\n        private Exception exception;\n\n        protected String doInBackground(String... urls) {\n            try {\n                String getResponse = post(\"http:\/\/www.roundsapp.com\/post\", bowlingJson(\"Me\", \"You\"));\n                return getResponse;\n            } catch (Exception e) {\n                this.exception = e;\n                return null;\n            }\n        }\n\n        protected void onPostExecute(String getResponse) {\n            System.out.println(getResponse);\n        }\n\n        private String post(String url, String json) throws IOException {\n            RequestBody body = RequestBody.create(JSON, json);\n            Request request = new Request.Builder()\n                    .url(url)\n                    .post(body)\n                    .build();\n            Response response = client.newCall(request).execute();\n            return response.body().string();\n        }\n    }\n    public String bowlingJson(String player1, String player2) {\n        return \"{'winCondition':'HIGH_SCORE',\"\n                + \"'name':'Bowling',\"\n                + \"'round':4,\"\n                + \"'lastSaved':1367702411696,\"\n                + \"'dateStarted':1367702378785,\"\n                + \"'players':[\"\n                + \"{'name':'\" + player1 + \"','history':[10,8,6,7,8],'color':-13388315,'total':39},\"\n                + \"{'name':'\" + player2 + \"','history':[6,10,5,10,10],'color':-48060,'total':41}\"\n                + \"]}\";\n    }\n}\n<\/pre>\n<h2>4. AndroidManifest.xml<\/h2>\n<p>The AndroidManifest.xml of our project is simple and contains the essential INTERNET permission:[ulp id='Ja8Orb5oPKdShcXt']<\/p>\n<p><em><span style=\"text-decoration: underline;\">AndroidManifest.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false,highlight:[4]\">&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    package=\"com.javacodegeeks.androidhttppostgetexample\"&gt;\n\n    &lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;\n\n    &lt;application\n        android:allowBackup=\"true\"\n        android:icon=\"@mipmap\/ic_launcher\"\n        android:label=\"@string\/app_name\"\n        android:supportsRtl=\"true\"\n        android:theme=\"@style\/AppTheme\"&gt;\n        &lt;activity\n            android:name=\".AndroidHttpPostGetActivity\"\n            android:label=\"@string\/app_name\"&gt;\n\n            &lt;intent-filter&gt;\n                &lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\n                &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\n            &lt;\/intent-filter&gt;\n\n        &lt;\/activity&gt;\n    &lt;\/application&gt;\n\n&lt;\/manifest\n&gt;\n<\/pre>\n<h2>5. build.gradle<\/h2>\n<p>The build.gradle of our project is simple and contains the OkHttp3 import.<\/p>\n<p><em><span style=\"text-decoration: underline;\">build.gradle<\/span><\/em><\/p>\n<pre class=\"brush:xml; wrap-lines:false,highlight:[26]\">apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion 23\n    buildToolsVersion \"23.0.3\"\n\n    defaultConfig {\n        applicationId \"com.javacodegeeks\"\n        minSdkVersion 14\n        targetSdkVersion 23\n        versionCode 1\n        versionName \"1.0\"\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n        }\n    }\n}\n\ndependencies {\n    compile fileTree(dir: 'libs', include: ['*.jar'])\n    testCompile 'junit:junit:4.12'\n    compile 'com.android.support:appcompat-v7:23.4.0'\n    compile 'com.squareup.okhttp3:okhttp:3.3.1'\n}\n<\/pre>\n<h2>6. Build, compile and run<\/h2>\n<p>When we build, compile and run our project, the main AndroidMultitouchExample should look like this:<\/p>\n<p><figure id=\"attachment_38788\" aria-describedby=\"caption-attachment-38788\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp2.png\"><img decoding=\"async\" class=\"size-full wp-image-38788\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp2.png\" alt=\"This is how our application looks.\" width=\"400\" height=\"711\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp2.png 400w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/androidOkhttp2-169x300.png 169w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-38788\" class=\"wp-caption-text\">This is how our application looks.<\/figcaption><\/figure><\/p>\n<h2>7. Download the Android Studio Project<\/h2>\n<p>This was an example of Android Http Get and Post Example with OkHttp.<\/p>\n<div class=\"download\"><strong>Download<br \/>\n<\/strong>You can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/AndroidHTTPPostGetExample.zip\"><strong>AndroidHTTPPostGetExample.zip<\/strong><\/a><\/div>\n<p>If you want to learn more about OkHttp you can visit the GitHub library <a href=\"http:\/\/square.github.io\/okhttp\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the OkHTTP 3.0 library, where OkHTTP is an Open Source project designed to be an efficient HTTP client. The usage of this library is very simple and &hellip;<\/p>\n","protected":false},"author":14,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1233,1389,1227,1523],"class_list":["post-38732","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-android-developement","tag-android-mobile-development","tag-android-studio","tag-okhttp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android Http Get and Post Example with OkHttp - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Http Get and Post Example with OkHttp - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-29T12:00:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-09T13:22:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Chryssa Aliferi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chryssa Aliferi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\"},\"author\":{\"name\":\"Chryssa Aliferi\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\"},\"headline\":\"Android Http Get and Post Example with OkHttp\",\"datePublished\":\"2016-06-29T12:00:07+00:00\",\"dateModified\":\"2023-11-09T13:22:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\"},\"wordCount\":452,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"keywords\":[\"Android developement\",\"android mobile development\",\"Android Studio\",\"okhttp\"],\"articleSection\":[\"Android\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\",\"name\":\"Android Http Get and Post Example with OkHttp - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2016-06-29T12:00:07+00:00\",\"dateModified\":\"2023-11-09T13:22:48+00:00\",\"description\":\"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Android Http Get and Post Example with OkHttp\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332\",\"name\":\"Chryssa Aliferi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg\",\"caption\":\"Chryssa Aliferi\"},\"description\":\"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Http Get and Post Example with OkHttp - Java Code Geeks","description":"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/","og_locale":"en_US","og_type":"article","og_title":"Android Http Get and Post Example with OkHttp - Java Code Geeks","og_description":"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the","og_url":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-06-29T12:00:07+00:00","article_modified_time":"2023-11-09T13:22:48+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Chryssa Aliferi","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Chryssa Aliferi","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/"},"author":{"name":"Chryssa Aliferi","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332"},"headline":"Android Http Get and Post Example with OkHttp","datePublished":"2016-06-29T12:00:07+00:00","dateModified":"2023-11-09T13:22:48+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/"},"wordCount":452,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","keywords":["Android developement","android mobile development","Android Studio","okhttp"],"articleSection":["Android"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/","url":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/","name":"Android Http Get and Post Example with OkHttp - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2016-06-29T12:00:07+00:00","dateModified":"2023-11-09T13:22:48+00:00","description":"In this example, we are going to learn how to execute simple Http Get and Post requests from our Android Application. We are going to make use of the","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/android-http-get-post-example-okhttp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"Android Http Get and Post Example with OkHttp"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/863144453b9fc15d4184d71833dcf332","name":"Chryssa Aliferi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/03\/Chryssa-Aliferi-96x96.jpg","caption":"Chryssa Aliferi"},"description":"Chryssa is a Computer Science graduate from Athens University of Economic and Business. During her studies, Chryssa carried out a great variety of projects ranging from networking to software engineering. She is very keen on front end development especially on mobile technologies and web applications. She has worked as a junior Software Engineer in the telecommunications area and currently works as an Android Developer.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/chryssa-aliferi\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=38732"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38732\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=38732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=38732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=38732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}