带参数的Httpclient POST(Httpclient POST with Parameters)
我真的很难通过HttpClient发送带有参数的POST请求:
private async Task<string> PostAsync(string parameterValue) { var ResponseMessage = await HttpClient.PostAsyncAsync(myUri, new FormUrlEncodedContent( new[] { new KeyValuePair<string, string>("parameter", parameterValue)
谢谢 - })); var httpResponse = await反序列化(ResponseMessage);
return Response.Token; }
我得到的是POST https://带有内容HTTP / 1.1参数的URI ,我需要的是https:// URI?parameter = PARAMETERVALUE HTTP / 1.1
有谁能够帮助我?
编辑:
谢谢 - 这就像:
private async Task<string> PostAsync(string parameterValue) { var ResponseMessage = await HttpClient.PostAsyncAsync(string.Format(myUri?parameter={0}, parameterValue), null)
I'm really stuck to send a POST request by HttpClient with Parameters:
private async Task<string> PostAsync(string parameterValue) { var ResponseMessage = await HttpClient.PostAsyncAsync(myUri, new FormUrlEncodedContent( new[] { new KeyValuePair<string, string>("parameter", parameterValue)
Thanks - })); var httpResponse = await Deserialize(ResponseMessage);
return Response.Token; }
What I get is POST https://URI with parameters in the content HTTP/1.1 and what I need is https://URI?parameter=PARAMETERVALUE HTTP/1.1
Can anybody help me?
EDIT:
Thanks - It's just like:
private async Task<string> PostAsync(string parameterValue) { var ResponseMessage = await HttpClient.PostAsyncAsync(string.Format(myUri?parameter={0}, parameterValue), null)
原文:https://stackoverflow.com/questions/35920189
最满意答案
根据您的示例,您可能正在寻找
split("(?<=\\})|(?=\\{)")
我们正在使用环视机制
(?<=\\})
拆分前面有}
地方(这意味着拆分后}
)(?=\\{)
拆分在{
之后(意味着在{
之前拆分)的地方但说实话,
split
甚至regex
可能不是你正在寻找的工具。 试着考虑构建自己的解析器/状态机。Based on your example it looks like you may be looking for
split("(?<=\\})|(?=\\{)")
We are using look-around mechanisms to
(?<=\\})
split at place which has}
before it (which means split after}
)(?=\\{)
split at place which has{
after it (which means split before{
)But to be honest
split
or evenregex
may not be tool you are looking for. Try to think of building your own parser/state machine instead.
相关问答
更多-
你可以使用Lookahind和Lookahind。 喜欢这个: System.out.println(Arrays.toString("a;b;c;d".split("(?<=;)"))); System.out.println(Arrays.toString("a;b;c;d".split("(?=;)"))); System.out.println(Arrays.toString("a;b;c;d".split("((?<=;)|(?=;))"))); 你会得到: [a;, b;, c;, d] [a, ...
-
根据您的示例,您可能正在寻找 split("(?<=\\})|(?=\\{)") 我们正在使用环视机制 (?<=\\})拆分前面有}地方(这意味着拆分后} ) (?=\\{)拆分在{之后(意味着在{之前拆分)的地方 但说实话, split甚至regex可能不是你正在寻找的工具。 试着考虑构建自己的解析器/状态机。 Based on your example it looks like you may be looking for split("(?<=\\})|(?=\\{)") We are usin ...
-
Java - 正则表达式来分割输入文本,但保留分隔符[复制](Java - Regex to split input text but keep delimiters [duplicate])[2023-11-27]
split不是Python的findall的Java模拟。 Matcher.find是。 Pattern stuff = Pattern.compile("[\\w']+|[\\s.,!?;:-]"); Matcher matcher = stuff.matcher("Hello, this isn't working!"); ListmatchList = new ArrayList (); while (matcher.find()) { matchList.ad ... -
在Java中拆分字符串,但在每个新字符串中保留分隔符(Split a string in Java, but keep the delimiters inside each new string)[2023-11-12]
使用Pattern和regex解决方案: 我会单独捕捉每个单词,或者在String之前和之后使用一个元素的单词 String str = "word1{word2}[word3](word4)\"word5\"'word6'"; Matcher m = Pattern.compile("(([{\\[(\"']\\w+[}\\])\"'])|(\\w+))").matcher(str); Listmatches = new ArrayList<>(); while (m.find()) ... -
对于大多数正则表达式,您可以通过将拆分表达式放在捕获组中来做一些事情。 new Regex("(<[^>]+>)").Split("test string") 生成带有项目的数组 test string (最后是一个空字符串) 如果你想找到标签内的东西,并且它们肯定没有以任何方式嵌套,你就可以做到 new Regex("(<[^>]+>[^<]*[^>]+>)").Split("test string") = test string ...
-
C ++用分隔符分割字符串并保留分隔符(C++ spliting string by delimiters and keeping the delimiters in result)[2022-05-22]
您可以在regex_iterator的示例之上构建解决方案。 例如,如果您知道您的分隔符是逗号,句点,分号和连字符,则可以使用正则表达式来捕获分隔符或一系列非分隔符: ([.,;-]|[^.,;-]+) 将其放入示例代码中,最终得到如下所示的结果 : #include#include #include int main () { // the following two lines are edited; the remainder are ... -
您可以使用lookarounds进行拆分: String[] tok = input.split("(?<=[+*/-])|(?=[+*/-])"); RegEx演示 说明: (?<=[+*/-]) # when preceding character is one of 4 arithmetic operators | # regex alternation (?=[+*/-]) # when following character is one of 4 arithmeti ...
-
您可以将您的puncts列表转换为正则表达式,以便按如下方式拆分: import re text = u"老師說:「你們要記住國父說的『青年要立志做大事,不要做大官』這句話。」" puncts = [u'!', u'"', u'#', u'$', u'%', u'&', u"'", u'(', u')', u'*', u'+', u',', u'-', u'.', u'/', u':', u';', u'<', u'=', u'>', u'?', u'@', u'[', u'\\', u']', u'^' ...
-
没有regexp,虽然我不确定它是更快还是更慢: vector
split(string& stringToSplit) { vector result; size_t pos = 0, lastPos = 0; while ((pos = stringToSplit.find_first_of(";,|", lastPos)) != string::npos) { result.push_back(stringToSplit. ... -
如何在多个分隔符上拆分字符串以保留一些分隔符?(How to split string on multiple delimiters keeping some delimiters?)[2022-01-25]
试试这个: $src='word1&word2 !word3 word4 &word5'; $arr=explode(' ',$src=preg_replace('/(?<=[\w])([&!])/',' $1',$src)); echo join('
',$arr); // present the result ... 首先将由单个字符[&!]组成的组的任何出现更改为' $1' (=本身,前面带有空格),然后使用该字符串explode()空白作为分隔符。 如果您需要处理多个空格作为单词之间的分隔符 ...