0

OpenSTf私は、Apache HTTP POSTで必要API POST/API/V1 /ユーザー/デバイス/ {シリアル}/remoteConnectOpenSTF API POST remoteConnect

要求を送信し、シリアルを渡しています。

 HttpPost request = new HttpPost("/api/v1/user/devices/"+ serial +"/remoteConnect"); 
HttpPost request1 = new HttpPost("/api/v1/user/devices/remoteConnect"); 

request.setConfig(config); 

       ArrayList<BasicNameValuePair> postParameters = new ArrayList<>(); 
       postParameters.add(new BasicNameValuePair("serial", serial)); 

       request.setEntity(new UrlEncodedFormEntity(postParameters)); 

要求とrequest1が動作しない、私は新しいHttpPostに APIのURLを作成する方法を理解していませんか?

答えて

1

アクセストークンを送信してもらえませんか?あなたのリクエストが失敗した理由かもしれません。アクセストークンは、OpenSTFの設定セクションで作成できます。

リクエストが失敗する可能性があるもう1つの問題は、デバイスを最初にユーザーに設定しないことです。

これは私のソリューションであり、私はRestassured Libraryを使用してPOSTリクエストを行っています。

String AccessToken = "Bearer e334457w44423e2342b6e5b8e5e0e723423488487b5cfe3"; 
String BaseUrl = "http://myopenstfapiurl.com/api/v1"; 
String deviceserial = "ABCDEF"; 

public void SetADeviceToUser() { 
    RestAssured.baseURI = BaseUrl; 
    RestAssured.given().contentType(ContentType.JSON).header("Authorization", AccessToken) 
     .body("{\"serial\": \"" + deviceserial + "\",\"timeout\": 0}").post("/user/devices") 
     .asString(); 
    } 

    public String GetRemoteUrlForDevice() { 
    RestAssured.baseURI = BaseUrl; 
    String response = RestAssured.given().contentType(ContentType.JSON) 
     .header("Authorization", AccessToken) 
     .post("/user/devices/" + deviceserial + "/remoteConnect").asString(); 

    System.out.println(response); 
    //Return the remoteConnectURL which will be used to connect to the device. 
    return JsonPath.parse(response).read("$.remoteConnectUrl"); 
    }