big update's coming
[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:** The request URL in a request message usually only consists of the path and the querystring.
23
24 <?php
25 $m = new http\Message;
26 $m->setType(http\Message::TYPE_REQUEST);
27 $m->setRequestMethod("GET");
28 $m->setRequestUrl("http://foo.bar/baz?q");
29 echo $m;
30 ?>
31
32 Yields:
33
34 GET http://foo.bar/baz?q HTTP/1.1
35
36 Maybe you did not really expect this, so let's try this:
37
38 <?php
39 $m = new http\Message;
40 $u = new http\Url("http://foo.bar/baz?q");
41 $m->setType(http\Message::TYPE_REQUEST);
42 $m->setRequestMethod("GET");
43 $m->setRequestUrl($u->path ."?". $u->query);
44 $m->setHeader("Host", $u->host);
45 echo $m;
46 ?>
47
48 Yields:
49
50 GET /baz?q HTTP/1.1
51 Host: foo.bar