replay get form stewgate

Dependencies:   EthernetNetIf NetServices mbed

Fork of HTTPClientExample by Donatien Garnier

Revision:
4:a81d4a6f6e29
Parent:
3:5964d831654c
--- a/HTTPClientExample.cpp	Thu Aug 05 15:12:04 2010 +0000
+++ b/HTTPClientExample.cpp	Sat Aug 31 07:55:46 2013 +0000
@@ -1,38 +1,67 @@
+#pragma import __use_all_ctype
+
 #include "mbed.h"
 #include "EthernetNetIf.h"
 #include "HTTPClient.h"
+#include "utf8tosjis.h"
+#include <string.h>
 
 EthernetNetIf eth;
 HTTPClient http;
-  
+Serial pc(USBTX, USBRX); // tx, rx
+
 int main() {
+    char  buf_s[256];
+    char  buf_u[256];
+
+    printf("Setting up...\r\n");
+    EthernetErr ethErr = eth.setup();
+    if(ethErr)
+    {
+        printf("Error %d in setup.\r\n", ethErr);
+        return -1;
+    }
+    printf("Setup OK\r\n");
+
+    HTTPText txt;
+    HTTPMap token;
+    token["_t"] = "";//input token
+    //token["msg"] = "test";  
+
+    HTTPResult r = http.post("http://stewgate-u.appspot.com/api/last_mention/", token, &txt);
 
-  printf("Setting up...\n");
-  EthernetErr ethErr = eth.setup();
-  if(ethErr)
-  {
-    printf("Error %d in setup.\n", ethErr);
-    return -1;
-  }
-  printf("Setup OK\n");
-  
-  HTTPText txt;
-  
-  HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt);
-  if(r==HTTP_OK)
-  {
-    printf("Result :\"%s\"\n", txt.gets()); 
-  }
-  else
-  {
-    printf("Error %d\n", r);
-  }
-  
-  while(1)
-  {
-  
-  }
-  
-  return 0;
-  
+    if(r==HTTP_OK)
+    {
+      printf("Result :\"%s\"\r\n", txt.gets()); 
+    }
+    else
+    {
+      printf("Error %d\r\n", r);
+    }
+
+    strcpy(buf_u, txt.gets());  
+    size_t sz;
+    // assuming UTF-8 is NULL terminated
+    sz = strlen(buf_u);
+    
+    printf("\r\nUTF-8:\r\n");
+    for(int i=0; i<sz; i++) {
+        printf("0x%02x ", buf_u[i]);
+    }
+
+    int len = utf8tosjis(buf_u, sz, buf_s, sizeof(buf_s));
+
+    printf("\r\nSJIS:\r\n");
+    if (len != -1) {
+        for(int i=0; i<len; i++) {
+            printf("0x%02x ", buf_s[i]);
+        }
+        printf("\r\n");
+    }
+    printf("%s", buf_s);
+    
+    while(1)
+    {
+    }
+    return 0;
 }