The User-agent field is mainly used for formatting the response accordingly (e.g. for mobile phones) and shouldn't result in an error code(4xx). The 405 you're getting means that the method used in the request (POST) is not allowed. If you examine the headers of the response from google.com you'll see "Allow: GET, HEAD" so you'll have to change the request method to either of those.
On a side note, if you're only going to be sending text and not binary data, you don't need the "multipart/form-data" content type.