@@ -277,13 +277,45 @@ export default class FetchInterceptor extends Base{
277277const status = mockItem . status ;
278278const statusText = HTTPStatusCodes [ status ] || '' ;
279279
280- const headers = typeof Headers === 'function'
281- ?new Headers ( { ...mockItem . headers , 'x-powered-by' :'http-request-mock' } )
282- :Object . entries ( { ...mockItem . headers , 'x-powered-by' :'http-request-mock' } ) ;
280+ const [ headers , contentType ] = ( ( ) => {
281+ const defaultContentType = 'application/json' ;
282+ if ( typeof Headers === 'function' ) {
283+ const headers = new Headers ( { ...mockItem . headers , 'x-powered-by' :'http-request-mock' } )
284+ return [ headers , headers . get ( 'content-type' ) || defaultContentType ] as const ;
285+ }
286+ const headers = Object . entries ( { ...mockItem . headers , 'x-powered-by' :'http-request-mock' } ) ;
287+ return [ headers , headers . find ( item => item [ 0 ] === 'content-type' ) ?. [ 1 ] || defaultContentType ] as const ;
288+ } ) ( )
283289
284- const body = typeof Blob === 'function'
285- ?new Blob ( [ typeof data === 'string' ?data :JSON . stringify ( data ) ] )
286- :data ;
290+ // 根据 content-type 判断 data 类型
291+ const body = ( ( ) => {
292+ if ( contentType . includes ( 'application/json' ) ) {
293+ const jsonStr = typeof data === 'string' ?data :JSON . stringify ( data ) ;
294+ return typeof Blob === 'function'
295+ ?new Blob ( [ jsonStr ] , { type :'application/json' } )
296+ :jsonStr ;
297+ } else if ( contentType . includes ( 'application/octet-stream' ) || contentType . includes ( 'image/' ) || contentType . includes ( 'application/pdf' ) ) {
298+ // 处理为 Blob 类型,确保 data 为可用类型
299+ let blobPart :BlobPart ;
300+ if ( typeof data === 'string' || data instanceof ArrayBuffer ) {
301+ blobPart = data ;
302+ } else if ( data instanceof Uint8Array ) {
303+ // 确保为标准 ArrayBuffer
304+ blobPart = data . buffer instanceof ArrayBuffer ?data . buffer :new Uint8Array ( data ) . buffer ;
305+ } else {
306+ blobPart = typeof data === 'object' ?JSON . stringify ( data ) :String ( data ) ;
307+ }
308+ return typeof Blob === 'function'
309+ ?new Blob ( [ blobPart ] , { type :contentType } )
310+ :blobPart ;
311+ } else {
312+ // 默认处理为字符串
313+ const str = typeof data === 'string' ?data :JSON . stringify ( data ) ;
314+ return typeof Blob === 'function'
315+ ?new Blob ( [ str ] , { type :'text/plain' } )
316+ :str ;
317+ }
318+ } ) ( )
287319
288320if ( typeof Response === 'function' ) {
289321const response = new Response ( body as BodyInit , { status, statusText, headers} ) ;