calendar 365 rest api 支持希腊字母

calendar 365 rest api greek letters support

我正在尝试使用 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"},

我设法解决了这个问题。问题出在我发送的编码上。如果有人发现这有帮助,则必须将 String 实体更改为这一行:

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