如何在webrequest URL中传递varible值?

时间:2016-08-11 17:58:11

标签: c# ssis servicenow

这是我的代码

 WebRequest req = WebRequest.Create("https://satellite.service-now.com/api/now/table/incident?sysparm_query=opened_atBETWEENjavascript:gs.dateGenerate('2016-07-01','00:00:00')@javascript:gs)=.dateGenerate('2016-08-31','23:59:59')");

此处代替日期' 2016-07-01'我想传递变量或字符串并传递该链接。我怎样才能在c#

中实现这个目标

1 个答案:

答案 0 :(得分:2)

// 5 days ago
DateTime variableDate = DateTime.Now.AddDays(-5);
// format it however you want
string variableDateText = variableDate.ToString("yyyy-MM-dd");

// concatenate it into your string
WebRequest req = WebRequest.Create("https://satellite.service-now.com/api/now/table/incident?sysparm_query=opened_atBETWEENjavascript:gs.dateGenerate('" + variableDateText + "','00:00:00')@javascript:gs)=.dateGenerate('2016-08-31','23:59:59')");

您可以搜索关于此的许多相关问题。