Sending iso-8859-1 chars from google apps script

2020-03-26 05:33发布

I'm trying to invoke a service that sends a sms from a google apps script. The service wants the data in iso 8859-1. The code below send a message with the åäö as bad chars.

function sendSMS() {

  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var cell = doc.getRange('b8');

  var payload = 
{
  "username" : "XXXX",
  "password" : "YYYY",
  "nr" : "0123123123",
  "type" : "text",
  "data" :  "Hello world...åäö" 

};

var options =
{
  "method" : "post",
  "payload" : payload
};

var response = UrlFetchApp.fetch("http://www.mosms.com/se/sms-send.php", options);
Browser.msgBox(response.getContentText());
}

function testFetch (){

var response = UrlFetchApp.fetch("http://www.google.com/");
Browser.msgBox(response.getContentText());

}

1条回答
闹够了就滚
2楼-- · 2020-03-26 06:28

As mentioned in the other question that Serge linked to in the comments, you can change the encoding of a string by first converting it to a Blob and then using the getDataAsString() method:

var result = Utilities.newBlob('Hello World').getDataAsString('ISO-8859-1');
查看更多
登录 后发表回答