Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Rafal Kowalski
    @tharpa
    Welcome to Matchmore iOS SDK!
    nico368
    @nico368

    Bonjour,

    J'ai un soucis, j'essai de crée un publication depuis mon serveur Glassfish, mais j'ai un handshake_failure, et je me demande si j'implement correctement

    mon code est le suivant:

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.Reader;
    import java.net.MalformedURLException;
    import java.net.ProtocolException;
    import java.net.URL;
    import java.net.URLEncoder;
    import java.util.Iterator;
    import java.util.LinkedHashMap;
    import java.util.Map;
    import javax.net.ssl.HttpsURLConnection;

    public class AndNico {

    public static void main(String[] args){
    try {
    AndNico.call_me();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static StringBuilder call_me() throws MalformedURLException, ProtocolException, IOException {

    URL url = new URL("https://api.matchmore.io/v5/devices/a2dee2ed-9996-41cf-af07-996c9a576472/publications");
    Map params = new LinkedHashMap<>();
    params.put("worldId", "waitingForCredentialsInMatchmore");
    params.put("deviceId", "a2dee2ed-9996-41cf-af07-996c9a576472");
    params.put("topic", "testTopic");
    params.put("range", 0);
    params.put("duration", 0);
    params.put("properties", "");
    StringBuilder postData = new StringBuilder();
    for (Iterator it = params.entrySet().iterator(); it.hasNext();) {
    Map.Entry param = (Map.Entry) it.next();
    if (postData.length() !=0) postData.append('&');
    postData.append(URLEncoder.encode((String) param.getKey(), "UTF-8"));
    postData.append('=');
    postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
    }
    byte[] postDataBytes = postData.toString().getBytes("UTF-8");
    HttpsURLConnection httpsCon = (HttpsURLConnection)url.openConnection();
    httpsCon.setRequestMethod("POST");
    httpsCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    httpsCon.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
    httpsCon.setDoOutput(true);
    httpsCon.getOutputStream().write(postDataBytes);
    Reader in = new BufferedReader(new InputStreamReader(httpsCon.getInputStream(), "UTF-8"));
    StringBuilder sb = new StringBuilder();
    for (int c; (c = in.read())>=0;)
    sb.append((char)c);
    String response = sb.toString();
    System.out.println(response);

    System.out.println(httpsCon.getResponseCode());
    System.out.println(httpsCon.getResponseMessage());
    System.out.println("did it work?");
    return null;
    }

    nico368
    @nico368
    sorry wrong thread