2016-05-10 7 views
0

私は春にはとても新しいです。休憩サービスから何かを得るのに問題があります。私が間違っていることに対する答えを得たいです。事前に感謝!Springで休憩サービスからの回答を得ることができない

これは私が答えを得ようとしている場所からの残りのサービスです: ここに私のコードです。

package testi; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.http.HttpEntity; 
import org.springframework.http.HttpHeaders; 
import org.springframework.http.HttpMethod; 
import org.springframework.http.MediaType; 
import org.springframework.http.ResponseEntity; 
import org.springframework.web.client.RestTemplate; 
import java.util.Arrays; 


@SpringBootApplication 
public class TestiApplication { 

public static void main(String[] args) { 
    SpringApplication.run(TestiApplication.class, args); 
} 

public void run(String... args) throws Exception { 

    RestTemplate restTemplate = new RestTemplate(); 

    //Asetettaan otsikkotietueet 
    HttpHeaders headers = new HttpHeaders(); 
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); 
    headers.setContentType(MediaType.APPLICATION_JSON); 
    headers.add("X-ESA-API-KEY", "ROBOT"); 

    HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); 
    System.out.println("Testing " + entity.getHeaders()); 

    String answer = restTemplate.postForObject("https://www.veikkaus.fi/api/v1/sport-games/draws?game-names=MULTISCORE", entity, String.class); 
    System.out.println(answer); 

    //ResponseEntity<String> response = restTemplate.exchange("https://www.veikkaus.fi/api/v1/sport-games/draws?game-names=MULTISCORE", HttpMethod.GET, entity, String.class); 
    //System.out.println(response); 

    } 
} 
+0

申し訳ありません、残りのサービスをここに追加するのを忘れてしまいました。 https://github.com/VeikkausOy/sport-games-robot/blob/master/README.md – Miira

+0

?あなたは例外を取得していますか?そうであれば、あなたの投稿にそれを含めてください。 – Kayaman

+0

あなたはどんな問題を抱えていますか? – reos

答えて

0

提供したAPIドキュメントは、アクセスしようとしているAPIがGETメソッドを使用していると思われるようです。 POSTメソッド(restTemplate.postForObject(...))でリクエストしています。

restTemplate.getForObject(...)でGETメソッドを使用してみてください。

一般に、REST呼び出しをデバッグするときは、応答本体に加えて応答状況コードも調べる必要があります。この場合、おそらく何が問題になったのかを示すHTTP 405エラーが発生しているはずです。

+0

GETメソッドを使用しなければならなかったので、皆さんに助けてくれてありがとうございました。restTemplate.exchange ther e。私は助けてくれたコマンドラインランナーも実装しました。みんなありがとう! – Miira

関連する問題