Android Question problems with HttpJob , PostString , SetContentType , send json

invaderwt

Member
Licensed User
Longtime User
I need send a block of json in a post situation.
How could I do that, I did a lot of tries like below
First Try
B4X:
Sub Button1_Click
Dim  job2 As HttpJob
  'Send a POST request
  job2.Initialize("Job2", Me)
  job2.PostString("http://www.mysite/users/sign_in/", "[email protected]&password=pass")
End Sub
Sub JobDone(job As HttpJob)
  ProgressDialogHide
  If job.Success Then
  ToastMessageShow ("SuccessFully Finish !", True)
  json.Initialize(job.GetString)
  'ShowData
  Log(job.GetString)
  job.Release
  Else
  Msgbox(job.ErrorMessage, "Error")
  End If
End Sub
second try
B4X:
Sub Button1_Click
Dim job1, job2, job3 As HttpJob
  'j.Download2("http://www.mysite/users/sign_in", Array As String("email", ""))

  'Send a POST request
  job2.Initialize("Job2", Me)
  'job2.PostString.SetContentType("application/json")
  Dim text As String
  text = "{'email':'user@','password':'p@ss'}"
  'job2.PostString("http://www.mysite/users/sign_in", text)
  job2.Download2("http://www.mysite/users/sign_in", Array As String ( "email","user@","password","p@ss"))
' job2.GetRequest.SetContentType("application/json")

  'Send a GET request
  ' job3.Initialize("Job3", Me)
  ' job3.Download("http://www.mysite/users/sign_in?email=shopping@mysite&password=p@ss")
End Sub

B4X:
Sub JobDone(job As HttpJob)
     ProgressDialogHide
 
     If job.Success Then
 
 
       ToastMessageShow ("SuccessFully Finish !", True)
       json.Initialize(job.GetString)
       'ShowData
       Log(job.GetString)
       job.Release
     Else
         Msgbox(job.ErrorMessage, "Error")
       End If
End Sub

I need do something like that but i really can´t send the post with a json some one know how do that?
He send a json and recive back a json.
Thank
B4X:
- curl -H 'Content-Type: application/json' -H 'Accept: applicatíon/json' -X POST http://www.mysite/users/sign_in -d '{"user": {"email": "user@", "password": "p@ss"}}'
{"id": 2 ,"email":"asd","segment":null,"authentication_token":"eLBJjasd9as7_9871923"}^
~ I
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

invaderwt

Member
Licensed User
Longtime User
Hi, now I can send the data but the data back to me, I can´t recive the json come only a html when I tried in the https://www.hurl.it/ come a json response
And the back end send me the correct line to send the pass and the user so now
B4X:
 text =  "usr[email]=mail&usr[pass]=pass"
response form website:
B4X:
{"email":"","password":null}

response for app:
B4X:
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
<!DOCTYPE html>
<html>
<head>
  <title>The page you were looking for doesn't exist (404)</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <style>
  body {
  background-color: #EFEFEF;
  color: #2E2F30;
  text-align: center;
  font-family: arial, sans-serif;
  margin: 0;
  }
  div.dialog {
  width: 95%;
  max-width: 33em;
  margin: 4em auto 0;
  }
  div.dialog > div {
  border: 1px solid #CCC;
  border-right-color: #999;
  border-left-color: #999;
  border-bottom-color: #BBB;
  border-top: #B00100 solid 4px;
  border-top-left-radius: 9px;
  border-top-right-radius: 9px;
  background-color: white;
  padding: 7px 12% 0;
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
  }
  h1 {
  font-size: 100%;
  color: #730E15;
  line-height: 1.5em;
  }
  div.dialog > p {
  margin: 0 0 1em;
  padding: 1em;
  background-color: #F7F7F7;
  border: 1px solid #CCC;
  border-right-color: #999;
  border-left-color: #999;
  border-bottom-color: #999;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  border-top-color: #DADADA;
  color: #666;
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
  }
  </style>
</head>
<body>
  <!-- This file lives in public/404.html -->
  <div class="dialog">
  <div>
  <h1>The page you were looking for doesn't exist.</h1>
  <p>You may have mistyped the address or the page may have moved.</p>
  </div>
  <p>If you are the application owner check the logs for more information.</p>
  </div>
</body>
</html>


Thanks for help me
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Without seeing what you are doing it is hard to give congrete answers...
As i can see in the log you posted...
B4X:
  <!-- This file lives in public/404.html -->
  <div class="dialog">
  <div>
  <h1>The page you were looking for doesn't exist.</h1>
  <p>You may have mistyped the address or the page may have moved.</p>
  </div>
  <p>If you are the application owner check the logs for more information.</p>
looks like the page you requested did not exists...
 
Upvote 0

invaderwt

Member
Licensed User
Longtime User
Hi , I think in the same way that you , but when this page come like a answer i had create a session on the website.
This is a error yet from the site
if I use this site :
login_img.PNG


Create a session but i can´t redo this in the app :(
 
Upvote 0
Top