{"id":1206,"date":"2024-04-04T18:20:41","date_gmt":"2024-04-04T09:20:41","guid":{"rendered":"https:\/\/test.media-sms.net\/api_st\/?p=1206"},"modified":"2024-05-09T12:41:14","modified_gmt":"2024-05-09T03:41:14","slug":"csv-java","status":"publish","type":"post","link":"https:\/\/media-sms.net\/developer\/console\/con-sample\/csv-java\/","title":{"rendered":"\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9CSV\u65b9\u5f0fJava"},"content":{"rendered":"\n<pre class=\"wp-block-code code-design-01\" style=\"font-size:16px\"><code>import org.apache.http.Header;\nimport org.apache.http.HttpEntity;\nimport org.apache.http.auth.UsernamePasswordCredentials;\nimport org.apache.http.client.methods.CloseableHttpResponse;\nimport org.apache.http.client.methods.HttpPost;\nimport org.apache.http.entity.ContentType;\nimport org.apache.http.entity.mime.MultipartEntityBuilder;\nimport org.apache.http.impl.auth.BasicScheme;\nimport org.apache.http.impl.client.CloseableHttpClient;\nimport org.apache.http.impl.client.HttpClientBuilder;\nimport org.apache.http.util.EntityUtils;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\n\n\/**\n * It's an example file which contains basic usage of CON's SMS API\n * Other parameters from CON's API specification can be used according to business logic and contract notes\n * This file must NOT be used for production services as is\n * Production version of API implementation must handle different error situations and http error codes\n *\/\n\npublic class test_CON_API3 {\n\n    private static final String USERNAME = \"maejima_test-u\"; \/\/ need real username\n    private static final String PASSWORD = \"password\"; \/\/ need real password\n    private static final String URL = \"https:\/\/www.******.jp\/api\/\"; \/\/ URL to the service\n \n    public static void main(String args&#91;]) {\n        send(\"test.jpg\", \"C:\/Users\/t-mae\/files\/\");\n    }\n\n    private static void send(String fileName, String folder) {\n\n        CloseableHttpClient httpClient = HttpClientBuilder.create()\n                .build();\n\n        try {\n            String pathToTheFile = folder + fileName;\n            HttpEntity requestEntity = MultipartEntityBuilder.create()\n                    .addTextBody(\"mobilenumber\", \"09018495712\")\n                    .addTextBody(\"smstext\", \"test {URL}\")\n                    .addBinaryBody(\"originalurl\", new File(pathToTheFile), ContentType.create(\"image\/jpeg\"), pathToTheFile)\n                    .build();\n\n            HttpPost post = new HttpPost(URL);\n\n            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(USERNAME, PASSWORD);\n            Header header = BasicScheme.authenticate(credentials, \"UTF-8\", false);\n            post.setHeader(header);\n\n            post.setEntity(requestEntity);\n            CloseableHttpResponse response = httpClient.execute(post);\n            HttpEntity httpEntity = response.getEntity();\n\n            if (null != httpEntity) {\n                File targetFile = new File(folder + \"api3_result.csv\");\n                FileOutputStream outstream = new FileOutputStream(targetFile);\n                httpEntity.writeTo(outstream);\n            }\n\n            EntityUtils.consume(httpEntity);\n            response.close();\n            httpClient.close();\n        } catch (Exception e) {\n            System.out.print(e);\n        } finally {\n            httpClient.getConnectionManager().shutdown();\n        }\n\n    }\n\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u305d\u306e\u4ed6\u306e\u8a00\u8a9e\u306b\u3064\u3044\u3066\u3082\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u306e\u4ed6\u306e\u8a00\u8a9e\u306b\u3064\u3044\u3066\u3082\u304a\u554f\u3044\u5408\u308f\u305b\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/posts\/1206"}],"collection":[{"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/comments?post=1206"}],"version-history":[{"count":6,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/posts\/1206\/revisions"}],"predecessor-version":[{"id":1509,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/posts\/1206\/revisions\/1509"}],"wp:attachment":[{"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/media?parent=1206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/categories?post=1206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/media-sms.net\/developer\/wp-json\/wp\/v2\/tags?post=1206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}