Android Question Traslate field Java to B4A

Discussion in 'Android Questions' started by MarcoRome, Jul 19, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed User

    Hi all.
    I have this code in java:

    Code:
    'HttpResponse<JsonNode> response = Unirest.post("https://xxxxxx/xxx-validate")
    '.header("X-Mashape-Key", "7ikZQqUI6Fmsh5SwxxxqiwToAEUp1J16Cojsnf7nqE2KYfsqu")
    '.header("Content-Type", "application/x-www-form-urlencoded")
    '.header("Accept", "application/json")
    '.field("number", "1-888-322-113333")
    '.asJson();
    translate in B4A is:

    Code:
    Dim job1 As HttpJob
        job1.Initialize(
    "MyJob", Me)
        job1.Download(
    "https://xxxxxx/xxx-validate")
        job1.GetRequest.SetHeader(
    "X-Mashape-Key""7ikZQqUI6Fmsh5Sw2lQfqiwxxx1J16Cojsnf7nqE2KYfsqu")
        job1.GetRequest.SetHeader(
    "Content-Type""application/json")
        job1.GetRequest.SetContentEncoding(
    "text/plain")
    but this line

    Code:
    '.field("number", "1-888-322-113333")
    as it is translated in B4A ??

    Thank you
    Marco
     
  2. DonManfred

    DonManfred Expert Licensed User

    i would try it this way (dont know if this works

    Code:
    Dim job1 As HttpJob
      job1.Initialize(
    "MyJob", Me)
      job1.Download(
    "https://xxxxxx/xxx-validate")
        job1.PostString(
    "https://xxxxxx/xxx-validate",$"{"number":"1-888-322-113333"}"$)
      job1.GetRequest.SetHeader(
    "X-Mashape-Key""7ikZQqUI6Fmsh5Sw2lQfqiwxxx1J16Cojsnf7nqE2KYfsqu")
      job1.GetRequest.SetHeader(
    "Content-Type""application/json")
      job1.GetRequest.SetContentEncoding(
    "text/plain")
     
  3. MarcoRome

    MarcoRome Expert Licensed User

    Thank DonMandred but dont work, the message is:
    Code:
    Response from server: {"api-parameter-name":"number","api-error":1,"api-parameter-type":"string","api-parameter-required":true,"api-error-msg":"MISSING OR INVALID PARAMETER"}
    in attachemnt example, so if you want try.
    Thank you again for your response.

    This is SITE for this service
     

    Attached Files:

  4. MarcoRome

    MarcoRome Expert Licensed User

    This is PHP Code:

    Code:
    // These code snippets use an open-source library. http://unirest.io/php
    $response = Unirest\Request::post(
    "https://neutrinoapi-phone-validate.p.mashape.com/phone-validate",
      
    array(
        
    "X-Mashape-Key" => "7ikZQqUI6Fmsh5Sw2lQfqiwToAEUp1J16Cojsnf7nqE2KYfsqu",
        
    "Content-Type" => "application/x-www-form-urlencoded",
        
    "Accept" => "application/json"
      ),
      
    array(
        
    "number" => "1-888-322-1133338"
      )
    );
    This is Java Code:

    Code:
    // These code snippets use an open-source library. http://unirest.io/java
    HttpResponse<JsonNode> response = Unirest.post("https://neutrinoapi-phone-validate.p.mashape.com/phone-validate")
    .header(
    "X-Mashape-Key""7ikZQqUI6Fmsh5Sw2lQfqiwToAEUp1J16Cojsnf7nqE2KYfsqu")
    .header(
    "Content-Type""application/x-www-form-urlencoded")
    .header(
    "Accept""application/json")
    .field(
    "number""1-888-322-1133338")
    .asJson();
    This is Curl:

    Code:
    curl -X POST --include 'https://neutrinoapi-phone-validate.p.mashape.com/phone-validate' \
      -H 'X-Mashape-Key: 7ikZQqUI6Fmsh5Sw2lQfqiwToAEUp1J16Cojsnf7nqE2KYfsqu' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -H 'Accept: application/json' \
      -d 'number=1-888-322-1133338'
     
  5. DonManfred

    DonManfred Expert Licensed User

    If i look at this site there should be a country-code too

    Code:
    curl -X POST --include 'https://neutrinoapi-phone-validate.p.mashape.com/phone-validate' \
      -H 'X-Mashape-Key: <required>' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -H 'Accept: application/json' \
      -d 'country-code=GB' \
      -d 'number=+447522123456'
    Code:
    Dim job1 As HttpJob
      job1.Initialize(
    "MyJob", Me)
      job1.Download(
    "https://xxxxxx/xxx-validate")
        job1.PostString(
    "https://xxxxxx/xxx-validate",$"{"number":"1-888-322-113333","country-code","GB"}"$)
      job1.GetRequest.SetHeader(
    "X-Mashape-Key""7ikZQqUI6Fmsh5Sw2lQfqiwxxx1J16Cojsnf7nqE2KYfsqu")
      job1.GetRequest.SetHeader(
    "Content-Type""application/json")
      job1.GetRequest.SetContentEncoding(
    "text/plain")
    maybe?
     
  6. MarcoRome

    MarcoRome Expert Licensed User

    Yes but this field is optional
     
  7. MarcoRome

    MarcoRome Expert Licensed User

    In this mode work ( without $ ):

    Code:
    job1.PostString("https://neutrinoapi-phone-validate.p.mashape.com/phone-validate","number=1-888-322-113333")
    Thank you for your support DonManfred ;)
     
    DonManfred likes this.
Loading...