title: Send a Post with url parameter with Retrofit 2
body: <p>I want to send a POST with Retrofit 2. The url has some parameters: </p>
  
  <pre><code> @Headers({
        "Accept: application/x-www-form-urlencoded;",
        "User-Agent: my-app"
   })
   @FormUrlEncoded
   @POST("server/directory/location.type")
  `public Call&lt;POJOStringValue&gt; dataWithUr(@Path("arg1") String arg1, @Path("arg2"), String arg2);         
  </code></pre>
  
  <p>The url looks like this </p>
  
  <blockquote>
    <p>www.website.com/server/directory/location.type?arg1=value1&amp;arg2=value2</p>
  </blockquote>
  
  <p>I was requested to use a POST request. The values (value1 and value2) are dynamic at runtime. I started the project with Xamarin using HttpClient and now I'm rewriting it in Java native. In C# all I had to do was to concact the strings and send the resulting string in a single Post.</p>
  
  <p>I tried to use @Path and the error was :</p>
  
  <blockquote>
    <p>"server/directory/location.type" does not contain "{arg1}". (parameter #1)</p>
  </blockquote>
  
  <p>Then, I tried to use @Query and the error was: </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Form-encoded method must contain at least one @Field.</p>
  </blockquote>
  
  <p>Finally I tried with @Field the request never gets any response (I sette the connection timeout to 5 seconds)</p>
  
  <p>Please help me, or tell me if I have to don't have any other choice but to use a GET request.</p>
  
  <p><strong>((EDIT))</strong>
  Here is my code for the setup of the client:</p>
  
  <pre><code>private static void setupClient(){
      final OkHttpClient client = new okhttp3.OkHttpClient.Builder()
              .connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
              .readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
              .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
              .retryOnConnectionFailure(false)
              .build();
  
  
      //define retrofit
      Retrofit retrofit = new Retrofit.Builder()
              .baseUrl(iXUtils.getUrl_())
              .addConverterFactory(GsonConverterFactory.create())
              .client(client)
              .build();
  
      this.client_ = retrofit.create(RequestInterface.class);
  }
  </code></pre>
  
  <p>The get() method:</p>
  
  <pre><code>public static RequestInterface get(){
      return this.client_;
  }
  </code></pre>
  
  <p>Here is how I call it:</p>
  
  <pre><code> public String callFunctionDB(String arg1,  String arg2){
      setupClient();
  
      Call&lt;POJOStringValue&gt; call  = get().dataWithUrlString(arg1, arg2);
      try {
          POJOStringValue response = call.execute().body();
          String value = response.getValue();
          int test = 0;
      } catch (IOException e) {
          String value = "it failded";
          e.printStackTrace();
      }
      return "test";
  } 
  </code></pre>
  
  <p>I put the test=0 to be able to put a breaking point, it never gets there. Plus I called the method "callFunctionDB" in a doInbackground to avoid the  android.os.NetworkOnMainThreadException.</p>