mdref.json config
[mdref/mdref-http] / http / Message / setRequestUrl.md
1 # http\Message http\Message::setRequestUrl(string $url)
2
3 Set the request URL of the message.
4 See http\Message::getRequestUrl() and http\Message::setRequestMethod().
5
6 ## Params:
7
8 * string $url
9 The request URL.
10
11 ## Returns:
12
13 * http\Message, self.
14
15 ## Throws:
16
17 * http\Exception\InvalidArgumentException
18 * http\Exception\BadMethodCallException
19
20 ## Example:
21
22 > ***NOTE:***
23 > The request URL in a request message usually only consists of the path and the querystring.
24
25 <?php
26 $m = new http\Message;
27 $m->setType(http\Message::TYPE_REQUEST);
28 $m->setRequestMethod("GET");
29 $m->setRequestUrl("http://foo.bar/baz?q");
30 echo $m;
31 ?>
32
33 Yields:
34
35 GET http://foo.bar/baz?q HTTP/1.1
36
37 Maybe you did not really expect this, so let's try this:
38
39 <?php
40 $m = new http\Message;
41 $u = new http\Url("http://foo.bar/baz?q");
42 $m->setType(http\Message::TYPE_REQUEST);
43 $m->setRequestMethod("GET");
44 $m->setRequestUrl($u->path ."?". $u->query);
45 $m->setHeader("Host", $u->host);
46 echo $m;
47 ?>
48
49 Yields:
50
51 GET /baz?q HTTP/1.1
52 Host: foo.bar