I'm travelling to UK for 6 months with Pakistani Passport. Can I apply for German Visa while in UK?
It might possible provided you fulfil certain conditions but its highly discouraged. Apply from your country of permanent residence.
To apply for a Schengen visa from the UK you must be a UK resident for at least three months. If this condition is not fulfilled, the Consulate of your country of preference will hardly take the application into consideration.
After 3 months of your stay you May apply, however
Non-residents such as travelers and tourists who plan on staying in the UK for 3 months or less should be discouraged from applying for a Schengen visa from within the UK. Instead, they should apply in their home country so that the application is processed, chances of getting a positive answer become greater.
Please note that if you are not a resident in the United Kingdom you should apply at the German Embassy in your country of residence.
Lastly, a very authentic source, VFS Global, states the following elibility
Applicant must at least meet the following criteria in order to be eligible to submit a Schengen visa application:
1.holding a valid passport/travel document
2.holding a valid UK residence permit. In case applicant holds a short stay visa, a C type visa (see example here), for the UK, then applicant needs to apply for a Schengen visa from his/her residence country.
3.applying for a short stay visa (Tourist: including Minors, Visitor Family/Friends, Business, EEA/EU and Swiss national family member or Airport Transit)
(The emphasis is mine)
This case does not fulfil eligibility requirement number 2