Scala Dispatch设置内容长度

时间:2015-07-07 09:03:29

标签: scala dispatch-scala

我有一个http发布呼叫,发送方式如下,

 url(API_HOST + URL).POST <:<
          headers <:<
          Map("Content-Type" -> "application/x-www-form-urlencoded") <<
          "name=SomeName&parentId=SomeParentID"

要添加Content-Lenght,计算字节的正确方法是什么,

Map("Content-Length" -> string.getBytes("UTF-8").length()toString)

我不确定这是否应该有效,或者是默认的表单调度

1 个答案:

答案 0 :(得分:0)

我不需要添加由底层库添加的内容,您必须做的唯一事情就是添加内容:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

   }

   @Override
  protected void onPause() {
  TimerTask backgroundCheck = new TimerTask() {

      @Override
      public void run() {
          ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
          List<RunningTaskInfo> tasks = am.getRunningTasks(1);
          if (!tasks.isEmpty()) {
             ComponentName topActivity = tasks.get(0).topActivity;
               if (!topActivity.getPackageName().equals(getApplicationContext().getPackageName())) {
                      // APP in background, do something

                }
            }

              // APP in foreground, do something else
   }
 };

 Timer isBackgroundChecker = new Timer();
 isBackgroundChecker.schedule(backgroundCheck, 1000, 1000);

 super.onPause();
}





}