Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 日历365 rest api希腊文字母支持_Java_Rest_Office365 - Fatal编程技术网

Java 日历365 rest api希腊文字母支持

Java 日历365 rest api希腊文字母支持,java,rest,office365,Java,Rest,Office365,我正在尝试使用calendar 365 rest api创建一个事件。我使用主题上的希腊字母正确地构造JSON。我得到201响应,事件被创建,但主题显示为????领域有没有办法回复希腊字母而不是问号?以下是我迄今为止所做的工作 @Path("/createevent") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML) public Response createEvent(

我正在尝试使用calendar 365 rest api创建一个事件。我使用主题上的希腊字母正确地构造JSON。我得到201响应,事件被创建,但主题显示为????领域有没有办法回复希腊字母而不是问号?以下是我迄今为止所做的工作

@Path("/createevent")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public Response createEvent(@FormParam("startTime") String startTime, @FormParam("endTime") String endTime, @FormParam("title") String title, @FormParam("eventBody") String eventBody, @FormParam("uniqueApiID") String uniqueApiID)

//public Response createEvent(@PathParam("startTime") String startTime, @PathParam("endTime") String endTime, @PathParam("title") String title, @PathParam("eventBody") String eventBody, @PathParam("uniqueApiID") String uniqueApiID)
{
    Response resp = null;
    String accessToken ="";
    Token token =null;
    String microsoftResponse = "";
    CloseableHttpResponse response=null;
    StringEntity stringEntity =null;


    try
    {
        byte titleByte[] = title.getBytes("UTF-8");
        String titleUTF= new String(titleByte,"UTF-8");
        token = DatabaseUtils.getaccessTokensAPI(uniqueApiID);
        accessToken=token.getAccessToken();
        if(accessToken=="")
        {
            microsoftResponse="Your unique id is not correct";
            resp = Response.status(404).entity(microsoftResponse).build();
        }
        else
        {

            eventBody ="{\n"+
                "  \"Subject\": \""+titleUTF+"\",\n"+
                "  \"Body\": {\n"+
                "   \"ContentType\": \"HTML\",\n"+
                "    \"Content\": \"I think it will meet our requirements!\"\n"+
                "  },\n"+
                "  \"Start\": \""+startTime+"\",\n"+
                "  \"End\": \""+endTime+"\",\n"+
                "  \"Attendees\": [\n"+
                "    {"+
                "      \"EmailAddress\": {\n"+
                "       \"Address\": \"my@mail.com\",\n"+
                "        \"Name\": \"Janet Schorr\"\n"+
                "     },\n"+
                "      \"Type\": \"Required\"\n"+
                "   }\n"+
                "  ]\n"+
                "}";

            CloseableHttpClient httpclient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost("https://outlook.office365.com/api/v1.0/me/events");
            httpPost.setHeader("authorization" ,"Bearer "+accessToken);
            httpPost.setHeader("charset" ,"UTF-8");
            httpPost.addHeader("Accept-Language", "el");
            stringEntity = new StringEntity(eventBody,ContentType.create("application/json"));
            httpPost.setEntity(stringEntity);

             response = httpclient.execute(httpPost);
             response.setHeader("charset" ,"UTF-8");
            InputStream  in=null;
            BufferedReader buffer=null;
            in= response.getEntity().getContent();
            int statusCode = response.getStatusLine().getStatusCode();
            buffer = new BufferedReader(new InputStreamReader(in, "UTF-8"));
              String s = "";
              while ((s = buffer.readLine()) != null) {
                microsoftResponse += s;
              }
              String mystring = new String(microsoftResponse.getBytes("UTF-8"),"UTF-8");
             // System.out.println(microsoftResponse);
              resp = Response.status(statusCode).entity(mystring).build();
        }

    }
    catch(Exception e)
    {
        e.printStackTrace();
        resp = Response.status(500).entity("error creating event").build();
    }


    return resp;

}

我用url编码的方式把它弄回来了。下面是希腊语中的事件

    Categories":[],"DateTimeCreated":"2015-03-26T13:38:37.2175553Z","DateTimeLastModified":"2015-03-26T13:38:37.5769451Z","Subject":"\u0388\u03bd\u03b1 \u03b1\u03c0\u03bb\u03cc \u03b3\u03b5\u03b3\u03bf\u03bd\u03cc\u03c2","BodyPreview":"\u0394\u03b5\u03b4\u03bf\u03bc\u03ad\u03bd\u03b1 \u03c4\u03bf\u03c5 \u03b3\u03b5\u03b3\u03bf\u03bd\u03cc\u03c4\u03bf\u03c2","Body":{"ContentType":"HTML","Content":"\u0394\u03b5\u03b4\u03bf\u03bc\u03ad\u03bd\u03b1 \u03c4\u03bf\u03c5 \u03b3\u03b5\u03b3\u03bf\u03bd\u03cc\u03c4\u03bf\u03c2"},"Importance":"Normal","HasAttachments":false,"Start":"2015-03-26T00:00:00Z","End":"2015-03-28T00:00:00Z","Location":{"DisplayName":"\u03b1\u03af\u03b8\u03bf\u03c5\u03c3\u03b1 \u03c3\u03c5\u03bd\u03b5\u03b4\u03c1\u03b9\u03ac\u03c3\u03b5\u03c9\u03bd"},

我设法解决了这个问题。问题在于我发送的编码。如果有人认为这很有用,则必须将字符串实体更改为此行:

stringEntity = new StringEntity(eventBody ,ContentType.create("application/json",Consts.UTF_8));

如果使用OWA或Outlook创建具有希腊主题的事件,然后使用日历API检索它,会发生什么情况?它和你想在这里设置的相比如何?