Android Question Http patch command

EdmundHerbert

Member
Licensed User
Longtime User
Hi I have application that uses http patch command

I see in HttpJob no support for example PatchString(XXXX

Has anybody used patch

Regards

Edmund
 

EdmundHerbert

Member
Licensed User
Longtime User
H Erel

I changed to OkHttp i now get error below

{"code":"BadArgument","message":"Invalid Media Type."}
Result: Unsupported Media Type
415 : Unsupported Media Type

I used same code with PutString that was working before as soon as I changed to OkHttp

B4X:
       Try       
       
           Dim GroupMap As Map
           GroupMap.Initialize 
           GroupMap.Put("name",EPersonGroupName.Text)     
           GroupMap.Put("userData",EPersonGroupUserData.Text)         
           Dim JSONGenerator As JSONGenerator       
           JSONGenerator.Initialize(GroupMap)
           Dim JSONstring As String
           JSONstring = JSONGenerator.ToString     
           Dim job2 As HttpJob         
           job2.Initialize("job2",Me) ' Create Person Group         
           job2.PutString("https://api.projectoxford.ai/face/v0/persongroups/"&       groupId,JSONstring)       
           job2.GetRequest.SetHeader("Content-Type","application/json")
           job2.GetRequest.SetHeader("Ocp-Apim-Subscription-Key","xxxxxxxxxxxxxxxxxxxxx")
         
         
       Catch
         ToastMessageShow("Comms with Oxford failed",False)
       End Try
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I changed to OkHttp i now get error below
you should privide more informations. In this case you should upload the changed bas file. Or post the relevant code from it
 
Upvote 0

EdmundHerbert

Member
Licensed User
Longtime User
I added this code to the HttpJob file which worked before I changed to OkHttp

As per my previous post this uses a REST service where I send Json data to Microsoft Azure Web Service.



B4X:
'Sends a PUT request with the given data as the put data.
Public Sub PutString(Link As String, Text As String)
   PutBytes(Link, Text.GetBytes("UTF8"))
End Sub

'Sends a PUT request with the given string as the put data
Public Sub PutBytes(Link As String, Data() As Byte)
   req.InitializePut2(Link, Data)
   CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
 
Last edited:
Upvote 0

EdmundHerbert

Member
Licensed User
Longtime User
Further information:

B4X:
@ECHO OFF

curl -v -X PUT "https://api.projectoxford.ai/face/v0/persongroups/{personGroupId}"
-H "Content-Type: application/json"
-H "Ocp-Apim-Subscription-Key: {subscription key}"

--data-ascii "{body}"

And Java Code:

B4X:
/ // This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample
{
    public static void main(String[] args)
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/face/v0/persongroups/{personGroupId}");


            URI uri = builder.build();
            HttpPut request = new HttpPut(uri);

            // Request body
            StringEntity reqEntity = new StringEntity("{body}");
            request.setEntity(reqEntity);

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null)
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
 
Upvote 0

EdmundHerbert

Member
Licensed User
Longtime User
More:

Face API


PersonGroup - Create a PersonGroup
Creates a new person group with a user-specified ID.

A person group is one of the most important parameters for the Identification API. The Identification searches person faces in a specified person group.

Http Method
PUT

Request URL
https://api.projectoxford.ai/face/v0/persongroups/{personGroupId}
Request parameters
personGroupId
string
User-provided personGroupId as a string. The valid characters include numbers, English letters in lower case, '-' and '_'. The maximum length of the personGroupId is 64.
Request headers
Content-Type (optional)
string
Media type of the body sent to the API.
Ocp-Apim-Subscription-Key
string
Subscription key which provides access to this API. Found in your Profile.
Request body
JSON fields in request body:

name
String
Person group display name. The maximum length is 128.
userData
String

User-provided data attached to the person group. The size limit is 16KB.
{
"name":"sample_group",
"userData":"user-provided data attached to the person group"
}
 
Upvote 0

EdmundHerbert

Member
Licensed User
Longtime User
Hi Erel I need Put, Patch, Get, File all HTTP commands, as I said before the put used to work after changing to OkHttp put and patch do not work
 
Upvote 0
Top