2016-12-01 14 views
0

如何在WebRequest中添加標頭。代碼header.add在.net內核中不工作

HttpWebRequest tRequest = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send"); 
      tRequest.Method = "POST"; 
      tRequest.ContentType = "application/json"; 
      var data = new 
      { 
       to = devicesId, 
       notification = new 
       { 
        body = "Fcm Test Notification", 
        title = "Test FCM", 
        sound = "Enabled" 
       }, 
       priority = "high" 
      }; 

      tRequest.Headers["Authorization: key={0}"] = appId; 

      tRequest.Headers["Sender: id={0}"] = senderId; 

我需要添加標頭來創建網絡請求。

感謝

+0

它的重複已經在這裏回答。 [在HttpWebRequest中添加自定義標頭](http://stackoverflow.com/a/37430845/2337983) – Ahmar

+0

[在HttpWebRequest中添加自定義標頭]的可能重複(http://stackoverflow.com/questions/8519788/add-custom -header-in-httpwebrequest) –

+0

不重複,閱讀我的答案 –

回答

相關問題