2016-09-22 6 views
0

を取得できませんが、私は、レスポンスの下残り、確実なJIRAのJava対応

残り、安心で認証を使用する方法
<div class="aui-message error"> 
    <span class="aui-icon icon-error"/> 
    <span class="error" id="error-authentication_failure_invalid_credentials"> 
     Sorry, we didn't recognize that username and password combination. Please double-check and try again. 
    </span> 
</div> 

を取得しています、コードの下に

import org.junit.Test; 
import org.omg.CORBA.Request; 

import com.jayway.restassured.RestAssured; 
import com.jayway.restassured.response.Response; 

import static com.jayway.restassured.RestAssured.*; 
import static org.hamcrest.Matchers.*; 

public class App 
{ 

    @Test 
    public void loginAuthentication() 
    { 

     RestAssured.authentication = basic("username", "password"); 

     Response resp = given(). 
      contentType("application/x-www-form-urlencoded"). 
     when(). 
      post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4"); 

     System.out.println(resp.prettyPrint()); 
    } 
} 

をご検討くださいREST-console(chrome plugin)を使用して投稿後リクエストを行うことができます。 何が間違っていますか?

私はこれでいくつかの助けを得ることを望みます。私は安心して試験を受けています。

答えて

0

は、応答ステータスが200.Changeそれであれば、あなたは成功時に200以外のエンドポイントを返すにサービスを提供する場合には、応答を取得します

Response resp = given(). 
      contentType("application/x-www-form-urlencoded").expect().response().statusCode(200). 
      when(). 
      post("https://unitrends.atlassian.net/login?username=Gayatri.londhe&password=GayatriA4"); 

...これを試してみてください。

は私が応答からatl_Tokenを抽出したい 、この

@BeforeClass 
public void setup() throws org.json.JSONException, IOException { 
    //Assigning base url 
    RestAssured.baseURI = "https://unitrends.atlassian.net/"; 
    //Assigning default port 
    RestAssured.port = <port> 
    RestAssured.basePath = "login"; 
    RestAssured.config = config().redirect(RedirectConfig.redirectConfig().followRedirects(true).and().allowCircularRedirects(true).maxRedirects(100)); 
} 
@Test 
public void testRestServiceAuthentication() { 
    //for a get method with basic authorization,its expecting response code 200 
    Response res = given().expect().response().statusCode(200).when().post("?username=Gayatri.londhe&password=GayatriA4"); 
    System.out.println(res.getBody().asString()); 
} 
+0

テストが正常に実行された試してみてください。どうやってやるの? –

+0

なぜ、私はこのapiがフィドラーでヒットするのを見ていないのですか? –

+0

'String出力=レスポンス.getBody()。asString(); System.out.println(出力); JSONObject obj =新しいJSONObject(出力); 文字列ステータス= String.valueOf(obj.get( "")); } これを使用できます。そのトークンはヘッダーとして送信されますか? –

関連する問題